-
Notifications
You must be signed in to change notification settings - Fork 1
/
userinfo_test.go
49 lines (38 loc) · 1.03 KB
/
userinfo_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
package cloudbeds_test
import (
"encoding/json"
"log"
"os"
"testing"
_ "github.com/joho/godotenv/autoload"
"github.com/omniboost/go-cloudbeds"
"golang.org/x/oauth2"
)
func TestUserinfo(t *testing.T) {
clientID := os.Getenv("OAUTH_CLIENT_ID")
clientSecret := os.Getenv("OAUTH_CLIENT_SECRET")
refreshToken := os.Getenv("OAUTH_REFRESH_TOKEN")
tokenURL := os.Getenv("OAUTH_TOKEN_URL")
oauthConfig := cloudbeds.NewOauth2Config()
oauthConfig.ClientID = clientID
oauthConfig.ClientSecret = clientSecret
// set alternative token url
if tokenURL != "" {
oauthConfig.Endpoint.TokenURL = tokenURL
}
token := &oauth2.Token{
RefreshToken: refreshToken,
}
// get http client with automatic oauth logic
httpClient := oauthConfig.Client(oauth2.NoContext, token)
client := cloudbeds.NewClient(httpClient)
client.SetDebug(true)
client.SetDisallowUnknownFields(true)
req := client.NewUserinfoRequest()
resp, err := req.Do()
if err != nil {
t.Error(err)
}
b, _ := json.MarshalIndent(resp, "", " ")
log.Println(string(b))
}