當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Config.PasswordCredentialsToken方法代碼示例

本文整理匯總了Golang中golang.org/x/oauth2.Config.PasswordCredentialsToken方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.PasswordCredentialsToken方法的具體用法?Golang Config.PasswordCredentialsToken怎麽用?Golang Config.PasswordCredentialsToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在golang.org/x/oauth2.Config的用法示例。


在下文中一共展示了Config.PasswordCredentialsToken方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Token

// Token refreshes the token by using a new client credentials request.
// tokens received this way do not include a refresh token
// Token returns a token or an error.
// Token must be safe for concurrent use by multiple goroutines.
// The returned Token must not be modified.
func (c *tokenSource) Token() (*oauth2.Token, error) {
	config := oauth2.Config{
		ClientID:     c.conf.ClientID,
		ClientSecret: c.conf.ClientSecret,
		Endpoint:     c.conf.Endpoint,
		Scopes:       c.conf.Scopes,
	}
	return config.PasswordCredentialsToken(c.ctx, c.conf.Username, c.conf.Password)
}
開發者ID:Ensighten,項目名稱:udnssdk,代碼行數:14,代碼來源:passwordcredentials.go

示例2: TokenForConfigAndCredentials

// TokenForConfigAndCredentials will return a token using the passed-in config
// and credentials, and an optional context. This is likely to be used if you
// need to obtain a token, but will be arranging your own transport. Otherwise,
// you probably want the http.Client that PasswordAuthenticatedClientFromConfig
// can give you.
func TokenForConfigAndCredentials(conf *oauth2.Config, username, password string, ctx context.Context) (*oauth2.Token, error) {
	if ctx == nil {
		ctx = context.Background()
	}

	token, err := conf.PasswordCredentialsToken(ctx, username, password)
	if err != nil {
		return nil, err
	}

	return token, nil
}
開發者ID:G5,項目名稱:gog5auth,代碼行數:17,代碼來源:client.go

示例3: ExamplePasswordCredentials

// Authenticate using OAuth2 password credentials
func ExamplePasswordCredentials() {
	apiUrl := "https://api.gb1.brightbox.com"
	// Brightbox username and password
	userName := "[email protected]"
	password := "mypassword"
	// Users can have multiple accounts, so you need to specify which one
	accountId := "acc-h3nbk"
	// These OAuth2 application credentials are public, distributed with the
	// cli.
	applicationId := "app-12345"
	applicationSecret := "mocbuipbiaa6k6c"

	// Setup OAuth2 authentication.
	conf := oauth2.Config{
		ClientID:     applicationId,
		ClientSecret: applicationSecret,
		Endpoint: oauth2.Endpoint{
			TokenURL: apiUrl + "/token",
		},
	}
	token, err := conf.PasswordCredentialsToken(oauth2.NoContext, userName, password)
	if err != nil {
		fmt.Println(err)
	}
	oc := conf.Client(oauth2.NoContext, token)

	// Setup connection to API
	client, err := brightbox.NewClient(apiUrl, accountId, oc)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Get a list of servers
	servers, err := client.Servers()
	if err != nil {
		fmt.Println(err)
		return
	}
	for _, server := range servers {
		fmt.Printf("id:%s name:%s\n", server.Id, server.Name)
	}
}
開發者ID:brightbox,項目名稱:gobrightbox,代碼行數:44,代碼來源:example_passwordcredentials_test.go

示例4: tokenisedAuth

func (authd *authdetails) tokenisedAuth() (*brightbox.Client, error) {
	conf := oauth2.Config{
		ClientID:     authd.APIClient,
		ClientSecret: authd.APISecret,
		Scopes:       infrastructureScope,
		Endpoint: oauth2.Endpoint{
			TokenURL: authd.tokenURL(),
		},
	}
	if authd.currentToken == nil {
		token, err := conf.PasswordCredentialsToken(oauth2.NoContext, authd.UserName, authd.password)
		if err != nil {
			return nil, err
		}
		authd.currentToken = token
	}
	oauthConnection := conf.Client(oauth2.NoContext, authd.currentToken)
	return brightbox.NewClient(authd.APIURL, authd.Account, oauthConnection)
}
開發者ID:brightbox,項目名稱:docker-machine-driver-brightbox,代碼行數:19,代碼來源:auth_options.go

示例5: tokenisedAuth

func (authd *authdetails) tokenisedAuth() (*brightbox.Client, error) {
	conf := oauth2.Config{
		ClientID:     authd.APIClient,
		ClientSecret: authd.APISecret,
		Scopes:       infrastructureScope,
		Endpoint: oauth2.Endpoint{
			TokenURL: authd.tokenURL(),
		},
	}
	if authd.currentToken == nil {
		log.Printf("[DEBUG] Obtaining authentication for user %s", authd.UserName)
		token, err := conf.PasswordCredentialsToken(oauth2.NoContext, authd.UserName, authd.password)
		if err != nil {
			return nil, err
		}
		authd.currentToken = token
	}
	log.Printf("[DEBUG] Refreshing current token if required")
	oauthConnection := conf.Client(oauth2.NoContext, authd.currentToken)
	return brightbox.NewClient(authd.APIURL, authd.Account, oauthConnection)
}
開發者ID:brightbox,項目名稱:terraform-provider-brightbox,代碼行數:21,代碼來源:auth_options.go


注:本文中的golang.org/x/oauth2.Config.PasswordCredentialsToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。