当前位置: 首页>>代码示例>>Golang>>正文


Golang Config.Client方法代码示例

本文整理汇总了Golang中golang.org/x/oauth2/clientcredentials.Config.Client方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.Client方法的具体用法?Golang Config.Client怎么用?Golang Config.Client使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在golang.org/x/oauth2/clientcredentials.Config的用法示例。


在下文中一共展示了Config.Client方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Example

// Authenticate using an API Client identifier and secret, and get a list of
// servers
func Example() {
	apiUrl := "https://api.gb1.brightbox.com"
	clientId := "cli-xxxxx"
	clientSecret := "somesecret"

	// Setup OAuth2 authentication
	conf := clientcredentials.Config{
		ClientID:     clientId,
		ClientSecret: clientSecret,
		Scopes:       []string{},
		TokenURL:     apiUrl + "/token",
	}
	oc := conf.Client(oauth2.NoContext)

	// Setup connection to API
	client, err := brightbox.NewClient(apiUrl, "", 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,代码行数:33,代码来源:example_apiclientauth_test.go

示例2: apiClientAuth

func (authd *authdetails) apiClientAuth() (*brightbox.Client, error) {
	conf := clientcredentials.Config{
		ClientID:     authd.APIClient,
		ClientSecret: authd.APISecret,
		Scopes:       infrastructureScope,
		TokenURL:     authd.tokenURL(),
	}
	oauthConnection := conf.Client(oauth2.NoContext)
	return brightbox.NewClient(authd.APIURL, authd.Account, oauthConnection)
}
开发者ID:brightbox,项目名称:docker-machine-driver-brightbox,代码行数:10,代码来源:auth_options.go

示例3: NewClient

func NewClient() *DevStudioApiClient {
	// Shout out to https://www.snip2code.com/Snippet/551369/Example-usage-of-https---godoc-org-golan
	baseUrl, _ := baseUrl()
	clientID, _ := clientID()
	clientSecret, _ := clientSecret()
	config := clientcredentials.Config{
		ClientID:     clientID,
		ClientSecret: clientSecret,
		TokenURL:     baseUrl + "/v1/auth/token",
	}
	// the client will update its token if it's expired
	client := config.Client(context.Background())
	return &DevStudioApiClient{Client: client, BaseUrl: baseUrl}
}
开发者ID:digideskio,项目名称:sabre-dev-studio-golang,代码行数:14,代码来源:sabredevstudio.go

示例4: apiClientAuth

func (authd *authdetails) apiClientAuth() (*brightbox.Client, error) {
	conf := clientcredentials.Config{
		ClientID:     authd.APIClient,
		ClientSecret: authd.APISecret,
		Scopes:       infrastructureScope,
		TokenURL:     authd.tokenURL(),
	}
	log.Printf("[DEBUG] Obtaining API client authorisation for client %s", authd.APIClient)
	oauthConnection := conf.Client(oauth2.NoContext)
	if authd.currentToken == nil {
		log.Printf("[DEBUG] Retrieving auth token for %s", conf.ClientID)
		token, err := conf.Token(oauth2.NoContext)
		if err != nil {
			return nil, err
		}
		authd.currentToken = token
	}
	return brightbox.NewClient(authd.APIURL, authd.Account, oauthConnection)
}
开发者ID:brightbox,项目名称:terraform-provider-brightbox,代码行数:19,代码来源:auth_options.go

示例5: OAuth2Client

func (c *Config) OAuth2Client(cmd *cobra.Command) *http.Client {
	c.Lock()
	defer c.Unlock()

	if c.oauth2Client != nil {
		return c.oauth2Client
	}

	oauthConfig := clientcredentials.Config{
		ClientID:     c.ClientID,
		ClientSecret: c.ClientSecret,
		TokenURL:     pkg.JoinURLStrings(c.ClusterURL, "/oauth2/token"),
		Scopes: []string{
			"core",
			"hydra",
		},
	}

	ctx := context.Background()
	if ok, _ := cmd.Flags().GetBool("skip-tls-verify"); ok {
		fmt.Println("Warning: Skipping TLS Certificate Verification.")
		ctx = context.WithValue(context.Background(), oauth2.HTTPClient, &http.Client{Transport: &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
		}})
	}

	_, err := oauthConfig.Token(ctx)
	if err != nil {
		fmt.Printf("Could not authenticate, because: %s\n", err)
		fmt.Println("Did you forget to log on? Run `hydra connect`.")
		fmt.Println("Did you run Hydra without a valid TLS certificate? Make sure to use the `--skip-tls-verify` flag.")
		fmt.Println("Did you know you can skip `hydra connect` when running `hydra host --dangerous-auto-logon`? DO NOT use this flag in production!")
		os.Exit(1)
	}

	c.oauth2Client = oauthConfig.Client(ctx)
	return c.oauth2Client
}
开发者ID:jemacom,项目名称:hydra,代码行数:38,代码来源:config.go


注:本文中的golang.org/x/oauth2/clientcredentials.Config.Client方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。