@@ -21,15 +21,18 @@ func Example_config() {
21
21
22
22
// Redirect user to consent page to ask for permission
23
23
// for the scopes specified above.
24
- url , _ := conf .AuthCodeURL ("" )
24
+ url , err := conf .AuthCodeURL ("" )
25
+ if err != nil {
26
+ log .Fatal (err )
27
+ }
25
28
fmt .Printf ("Visit the URL for the auth dialog: %v" , url )
26
29
27
30
// Use the exchange code that is handled by the redirect URL.
28
31
// NewTransportWithCode will do the handshake to retrieve
29
32
// an access token and iniate a Transport that is
30
33
// authorized and authenticated the retrieved token.
31
34
var exchangeCode string
32
- fmt .Scanln (& exchangeCode )
35
+ fmt .Scan (& exchangeCode )
33
36
t , err := conf .NewTransportWithCode (exchangeCode )
34
37
if err != nil {
35
38
log .Fatal (err )
@@ -38,7 +41,7 @@ func Example_config() {
38
41
// You can use t to initiate a new http.Client and
39
42
// start making authenticated requests.
40
43
client := http.Client {Transport : t }
41
- client .Get ("https://host/path " )
44
+ client .Get ("... " )
42
45
43
46
// Alternatively, you can initiate a new transport
44
47
// with tokens from a cache.
@@ -55,11 +58,11 @@ func Example_config() {
55
58
log .Fatal (err )
56
59
}
57
60
client = http.Client {Transport : t }
58
- client .Get ("https://host/path " )
61
+ client .Get ("... " )
59
62
}
60
63
61
64
func Example_jWTConfig () {
62
- conf , _ := NewJWTConfig (& JWTOptions {
65
+ conf , err := NewJWTConfig (& JWTOptions {
63
66
Email : "xxx@developer.gserviceaccount.com" ,
64
67
// The path to the pem file. If you have a p12 file instead, you
65
68
// can use `openssl` to export the private key into a pem file.
@@ -68,18 +71,21 @@ func Example_jWTConfig() {
68
71
Scopes : []string {"SCOPE1" , "SCOPE2" },
69
72
},
70
73
"https://provider.com/o/oauth2/token" )
74
+ if err != nil {
75
+ log .Fatal (err )
76
+ }
71
77
72
78
// Initiate an http.Client, the following GET request will be
73
79
// authorized and authenticated on the behalf of
74
80
// xxx@developer.gserviceaccount.com.
75
81
client := http.Client {Transport : conf .NewTransport ()}
76
- client .Get ("https://host/path " )
82
+ client .Get ("... " )
77
83
78
84
// If you would like to impersonate a user, you can
79
85
// create a transport with a subject. The following GET
80
86
// request will be made on the behalf of user@example.com.
81
87
client = http.Client {Transport : conf .NewTransportWithUser ("user@example.com" )}
82
- client .Get ("https://host/path " )
88
+ client .Get ("... " )
83
89
84
90
// Alternatively you can iniate a transport with
85
91
// a token read from the cache.
@@ -93,5 +99,5 @@ func Example_jWTConfig() {
93
99
client = http.Client {Transport : t }
94
100
// The following request will be authorized by the token
95
101
// retrieved from the cache.
96
- client .Get ("https://host/path " )
102
+ client .Get ("... " )
97
103
}
0 commit comments