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) + } +}