forked from Mirrors/oauth2
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>
This commit is contained in:
parent
8cf58155e4
commit
efb10a3061
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue