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>
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 @@
"context"
"fmt"
"log"
+ "net/http"
+ "time"
"golang.org/x/oauth2"
)
@@ -45,3 +47,25 @@
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)
+ }
+}