-
Notifications
You must be signed in to change notification settings - Fork 6
/
oauth.go
51 lines (41 loc) · 974 Bytes
/
oauth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"encoding/json"
"os"
"golang.org/x/oauth2"
githuboauth "golang.org/x/oauth2/github"
)
var (
OAuthConf = &oauth2.Config{
ClientID: "d103e51684009fc22250",
ClientSecret: "63079590549474872a6b656aed3c4aaecb8a3efc",
Scopes: []string{"user:email", "repo"},
Endpoint: githuboauth.Endpoint,
}
OAuthStateString = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
)
func isLoggedIn() bool {
_, err := os.Stat("token.json")
return !os.IsNotExist(err)
}
func loadToken() (*oauth2.Token, error) {
tokenFile, err := os.Open("token.json")
if err != nil {
return nil, err
}
token := &oauth2.Token{}
defer tokenFile.Close()
err = json.NewDecoder(tokenFile).Decode(token)
if err != nil {
return nil, err
}
return token, err
}
func saveToken(token *oauth2.Token) error {
tokenFile, err := os.Create("token.json")
if err != nil {
return err
}
defer tokenFile.Close()
return json.NewEncoder(tokenFile).Encode(token)
}