-
Notifications
You must be signed in to change notification settings - Fork 1
/
gauth_test.go
55 lines (43 loc) · 1015 Bytes
/
gauth_test.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
52
53
54
55
package gauth_test
import (
"os"
"reflect"
"testing"
"github.com/oneee-playground/gauth-go"
)
func TestGAuth(t *testing.T) {
clientID := os.Getenv("CLIENT_ID")
clientSecret := os.Getenv("CLIENT_SECRET")
redirectURI := os.Getenv("REDIRECT_URI")
email := os.Getenv("EMAIL")
password := os.Getenv("PASSWORD")
client := gauth.NewDefaultClient(gauth.ClientOpts{
ClientID: clientID,
ClientSecret: clientSecret,
RedirectURI: redirectURI,
})
code, err := client.IssueCode(email, password)
if err != nil {
t.Fatal(err)
}
access, refresh, err := client.IssueToken(code)
if err != nil {
t.Fatal(err)
}
userInfo, err := client.GetUserInfo(access)
if err != nil {
t.Fatal(err)
}
access, _, err = client.ReIssueToken(refresh)
if err != nil {
t.Fatal(err)
}
t.Log(access)
newUserInfo, err := client.GetUserInfo(access)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(userInfo, newUserInfo) {
t.Fatalf("userInfo deosn't match: %v %v", userInfo, newUserInfo)
}
}