From c310d5c9d2d5722ce00d5c961d698fab1eb97ad1 Mon Sep 17 00:00:00 2001 From: "jonreiter@gmail.com" Date: Tue, 28 Jan 2020 10:46:34 +0800 Subject: [PATCH 1/2] clientcredentials: add example --- clientcredentials/example_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 clientcredentials/example_test.go diff --git a/clientcredentials/example_test.go b/clientcredentials/example_test.go new file mode 100644 index 000000000..e026030bc --- /dev/null +++ b/clientcredentials/example_test.go @@ -0,0 +1,28 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package oauth2_test + +import ( + "context" + + "golang.org/x/oauth2" +) + +func ExampleConfig() { + ctx := context.Background() + conf := &oauth2.Config{ + ClientID: "YOUR_CLIENT_ID", + ClientSecret: "YOUR_CLIENT_SECRET", + Scopes: []string{"SCOPE1", "SCOPE2"}, + Endpoint: oauth2.Endpoint{ + TokenURL: "https://provider.com/o/oauth2/token", + }, + } + + // For the clientcredentials flow simply get a client from + // the Config directly. + client := conf.Client(ctx, tok) + client.Get("...") +} From 3ffadc1268828016a6b658a089f30c97a8670c1f Mon Sep 17 00:00:00 2001 From: "jonreiter@gmail.com" Date: Wed, 29 Jan 2020 07:15:41 +0800 Subject: [PATCH 2/2] cla signed and small fixes --- clientcredentials/example_test.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/clientcredentials/example_test.go b/clientcredentials/example_test.go index e026030bc..8f4c4fc2c 100644 --- a/clientcredentials/example_test.go +++ b/clientcredentials/example_test.go @@ -2,27 +2,25 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package oauth2_test +package clientcredentials_test import ( "context" - "golang.org/x/oauth2" + "golang.org/x/oauth2/clientcredentials" ) func ExampleConfig() { ctx := context.Background() - conf := &oauth2.Config{ + conf := &clientcredentials.Config{ ClientID: "YOUR_CLIENT_ID", ClientSecret: "YOUR_CLIENT_SECRET", Scopes: []string{"SCOPE1", "SCOPE2"}, - Endpoint: oauth2.Endpoint{ - TokenURL: "https://provider.com/o/oauth2/token", - }, + TokenURL: "https://provider.com/o/oauth2/token", } // For the clientcredentials flow simply get a client from // the Config directly. - client := conf.Client(ctx, tok) + client := conf.Client(ctx) client.Get("...") }