6
6
"os"
7
7
8
8
"github.com/int128/oauth2cli"
9
+ "github.com/pkg/browser"
9
10
"golang.org/x/oauth2"
10
11
"golang.org/x/oauth2/google"
11
12
"golang.org/x/sync/errgroup"
@@ -16,7 +17,11 @@ func main() {
16
17
ctx := context .Background ()
17
18
clientID , clientSecret := os .Getenv ("GOOGLE_CLIENT_ID" ), os .Getenv ("GOOGLE_CLIENT_SECRET" )
18
19
if clientID == "" || clientSecret == "" {
19
- log .Fatalf ("You need to set GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET" )
20
+ log .Fatalf (`You need to set oauth2 credentials.
21
+ Open https://console.cloud.google.com/apis/credentials and create a client. And then,
22
+ export GOOGLE_CLIENT_ID=xxx.apps.googleusercontent.com
23
+ export GOOGLE_CLIENT_SECRET=xxx
24
+ ` )
20
25
}
21
26
22
27
ready := make (chan string , 1 )
@@ -28,7 +33,9 @@ func main() {
28
33
return nil
29
34
}
30
35
log .Printf ("Open %s" , url )
31
- // you can open the browser here
36
+ if err := browser .OpenURL (url ); err != nil {
37
+ log .Printf ("could not open the browser: %s" , err )
38
+ }
32
39
return nil
33
40
case err := <- ctx .Done ():
34
41
return xerrors .Errorf ("context done while waiting for authorization: %w" , err )
@@ -48,8 +55,7 @@ func main() {
48
55
if err != nil {
49
56
return xerrors .Errorf ("could not get a token: %w" , err )
50
57
}
51
- log .Printf ("Got a token: %+v" , token )
52
- log .Printf ("Your token is valid until %s" , token .Expiry )
58
+ log .Printf ("You got a valid token until %s" , token .Expiry )
53
59
return nil
54
60
})
55
61
if err := eg .Wait (); err != nil {
0 commit comments