Skip to content

Commit 15adf1b

Browse files
committed
Fix for taking screencast
1 parent 74a6a5f commit 15adf1b

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/.idea
2+
3+
/example/example

example/main.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77

88
"github.com/int128/oauth2cli"
9+
"github.com/pkg/browser"
910
"golang.org/x/oauth2"
1011
"golang.org/x/oauth2/google"
1112
"golang.org/x/sync/errgroup"
@@ -16,7 +17,11 @@ func main() {
1617
ctx := context.Background()
1718
clientID, clientSecret := os.Getenv("GOOGLE_CLIENT_ID"), os.Getenv("GOOGLE_CLIENT_SECRET")
1819
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+
`)
2025
}
2126

2227
ready := make(chan string, 1)
@@ -28,7 +33,9 @@ func main() {
2833
return nil
2934
}
3035
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+
}
3239
return nil
3340
case err := <-ctx.Done():
3441
return xerrors.Errorf("context done while waiting for authorization: %w", err)
@@ -48,8 +55,7 @@ func main() {
4855
if err != nil {
4956
return xerrors.Errorf("could not get a token: %w", err)
5057
}
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)
5359
return nil
5460
})
5561
if err := eg.Wait(); err != nil {

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module github.com/int128/oauth2cli
22

33
require (
4+
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
45
golang.org/x/oauth2 v0.0.0-20190319182350-c85d3e98c914
56
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4
67
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ cloud.google.com/go v0.34.0 h1:eOI3/cP2VTU6uZLDYAoic+eyzzB9YyGmJ7eIjl8rOPg=
22
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
33
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
44
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
5+
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98=
6+
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
57
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
68
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg=
79
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

0 commit comments

Comments
 (0)