summaryrefslogtreecommitdiff
path: root/example_test.go
diff options
context:
space:
mode:
authorJaana Burcu Dogan <jbd@google.com>2017-03-02 12:04:53 -0800
committerJaana Burcu Dogan <jbd@google.com>2017-03-02 20:23:04 +0000
commitefb10a30610e617dbb17fc243f4cc61a8cfa2903 (patch)
tree9a67112c0c8a70ec41643af66b470f6f08c15234 /example_test.go
parent8cf58155e4a90a3a73149652cc36528e892c58cf (diff)
downloadgolang-x-oauth2-efb10a30610e617dbb17fc243f4cc61a8cfa2903.tar.gz
oauth2: add example how to use a custom HTTP client
Change-Id: Iffff423c167610c80e8dd1c51945c32b781e8653 Reviewed-on: https://go-review.googlesource.com/37695 Reviewed-by: Chris Broadfoot <cbro@golang.org>
Diffstat (limited to 'example_test.go')
-rw-r--r--example_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/example_test.go b/example_test.go
index d861fe7..378c70d 100644
--- a/example_test.go
+++ b/example_test.go
@@ -8,6 +8,8 @@ import (
"context"
"fmt"
"log"
+ "net/http"
+ "time"
"golang.org/x/oauth2"
)
@@ -45,3 +47,25 @@ func ExampleConfig() {
client := conf.Client(ctx, tok)
client.Get("...")
}
+
+func ExampleHTTPClient() {
+ hc := &http.Client{Timeout: 2 * time.Second}
+ ctx := context.WithValue(context.Background(), oauth2.HTTPClient, hc)
+
+ conf := &oauth2.Config{
+ ClientID: "YOUR_CLIENT_ID",
+ ClientSecret: "YOUR_CLIENT_SECRET",
+ Scopes: []string{"SCOPE1", "SCOPE2"},
+ Endpoint: oauth2.Endpoint{
+ AuthURL: "https://provider.com/o/oauth2/auth",
+ TokenURL: "https://provider.com/o/oauth2/token",
+ },
+ }
+
+ // Exchange request will be made by the custom
+ // HTTP client, hc.
+ _, err := conf.Exchange(ctx, "foo")
+ if err != nil {
+ log.Fatal(err)
+ }
+}