github.com/gophercloud/gophercloud@v1.11.0/openstack/identity/v3/extensions/oauth1/doc.go (about)

     1  /*
     2  Package oauth1 enables management of OpenStack OAuth1 tokens and Authentication.
     3  
     4  Example to Create an OAuth1 Consumer
     5  
     6  	createConsumerOpts := oauth1.CreateConsumerOpts{
     7  		Description: "My consumer",
     8  	}
     9  	consumer, err := oauth1.CreateConsumer(identityClient, createConsumerOpts).Extract()
    10  	if err != nil {
    11  		panic(err)
    12  	}
    13  
    14  	// NOTE: Consumer secret is available only on create response
    15  	fmt.Printf("Consumer: %+v\n", consumer)
    16  
    17  Example to Request an unauthorized OAuth1 token
    18  
    19  	requestTokenOpts := oauth1.RequestTokenOpts{
    20  		OAuthConsumerKey:     consumer.ID,
    21  		OAuthConsumerSecret:  consumer.Secret,
    22  		OAuthSignatureMethod: oauth1.HMACSHA1,
    23  		RequestedProjectID:   projectID,
    24  	}
    25  	requestToken, err := oauth1.RequestToken(identityClient, requestTokenOpts).Extract()
    26  	if err != nil {
    27  		panic(err)
    28  	}
    29  
    30  	// NOTE: Request token secret is available only on request response
    31  	fmt.Printf("Request token: %+v\n", requestToken)
    32  
    33  Example to Authorize an unauthorized OAuth1 token
    34  
    35  	authorizeTokenOpts := oauth1.AuthorizeTokenOpts{
    36  		Roles: []oauth1.Role{
    37  			{Name: "member"},
    38  		},
    39  	}
    40  	authToken, err := oauth1.AuthorizeToken(identityClient, requestToken.OAuthToken, authorizeTokenOpts).Extract()
    41  	if err != nil {
    42  		panic(err)
    43  	}
    44  
    45  	fmt.Printf("Verifier ID of the unauthorized Token: %+v\n", authToken.OAuthVerifier)
    46  
    47  Example to Create an OAuth1 Access Token
    48  
    49  	accessTokenOpts := oauth1.CreateAccessTokenOpts{
    50  		OAuthConsumerKey:     consumer.ID,
    51  		OAuthConsumerSecret:  consumer.Secret,
    52  		OAuthToken:           requestToken.OAuthToken,
    53  		OAuthTokenSecret:     requestToken.OAuthTokenSecret,
    54  		OAuthVerifier:        authToken.OAuthVerifier,
    55  		OAuthSignatureMethod: oauth1.HMACSHA1,
    56  	}
    57  	accessToken, err := oauth1.CreateAccessToken(identityClient, accessTokenOpts).Extract()
    58  	if err != nil {
    59  		panic(err)
    60  	}
    61  
    62  	// NOTE: Access token secret is available only on create response
    63  	fmt.Printf("OAuth1 Access Token: %+v\n", accessToken)
    64  
    65  Example to List User's OAuth1 Access Tokens
    66  
    67  	allPages, err := oauth1.ListAccessTokens(identityClient, userID).AllPages()
    68  	if err != nil {
    69  		panic(err)
    70  	}
    71  	accessTokens, err := oauth1.ExtractAccessTokens(allPages)
    72  	if err != nil {
    73  		panic(err)
    74  	}
    75  
    76  	for _, accessToken := range accessTokens {
    77  		fmt.Printf("Access Token: %+v\n", accessToken)
    78  	}
    79  
    80  Example to Authenticate a client using OAuth1 method
    81  
    82  	client, err := openstack.NewClient("http://localhost:5000/v3")
    83  	if err != nil {
    84  		panic(err)
    85  	}
    86  
    87  	authOptions := &oauth1.AuthOptions{
    88  		// consumer token, created earlier
    89  		OAuthConsumerKey:    consumer.ID,
    90  		OAuthConsumerSecret: consumer.Secret,
    91  		// access token, created earlier
    92  		OAuthToken:           accessToken.OAuthToken,
    93  		OAuthTokenSecret:     accessToken.OAuthTokenSecret,
    94  		OAuthSignatureMethod: oauth1.HMACSHA1,
    95  	}
    96  	err = openstack.AuthenticateV3(client, authOptions, gophercloud.EndpointOpts{})
    97  	if err != nil {
    98  		panic(err)
    99  	}
   100  
   101  Example to Create a Token using OAuth1 method
   102  
   103  	var oauth1Token struct {
   104  		tokens.Token
   105  		oauth1.TokenExt
   106  	}
   107  
   108  	createOpts := &oauth1.AuthOptions{
   109  		// consumer token, created earlier
   110  		OAuthConsumerKey:    consumer.ID,
   111  		OAuthConsumerSecret: consumer.Secret,
   112  		// access token, created earlier
   113  		OAuthToken:           accessToken.OAuthToken,
   114  		OAuthTokenSecret:     accessToken.OAuthTokenSecret,
   115  		OAuthSignatureMethod: oauth1.HMACSHA1,
   116  	}
   117  	err := tokens.Create(identityClient, createOpts).ExtractInto(&oauth1Token)
   118  	if err != nil {
   119  		panic(err)
   120  	}
   121  */
   122  package oauth1