-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
66 lines (56 loc) · 2.26 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2021 AccelByte Inc. All Rights Reserved.
// This is licensed software from AccelByte Inc, for limitations
// and restrictions contact your company contract manager.
package main
import (
"fmt"
"time"
"github.com/AccelByte/accelbyte-go-sdk/iam-sdk/pkg/iamclient/o_auth2_0_extension"
"github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/repository"
"github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/utils/auth"
"github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/factory"
"github.com/AccelByte/accelbyte-go-sdk/services-api/pkg/service/iam"
)
var (
// use the default config and token implementation
configRepo = *auth.DefaultConfigRepositoryImpl()
tokenRepo = *auth.DefaultTokenRepositoryImpl()
refreshRepo repository.RefreshTokenRepository = &auth.RefreshTokenImpl{AutoRefresh: false, RefreshRate: 0.01} // Force refresh with shorter time span
)
func main() {
// prepare the IAM Oauth service
oauth := &iam.OAuth20Service{
Client: factory.NewIamClient(&configRepo),
ConfigRepository: &configRepo,
TokenRepository: &tokenRepo,
RefreshTokenRepository: refreshRepo, // Refresh configured here
}
clientId := oauth.ConfigRepository.GetClientId()
clientSecret := oauth.ConfigRepository.GetClientSecret()
fmt.Println("This will print every 5 seconds")
for {
err := oauth.LoginOrRefreshClient(&clientId, &clientSecret)
if err != nil {
fmt.Println("failed login client")
} else {
fmt.Println("successful login")
}
// get the token
token, _ := oauth.TokenRepository.GetToken()
fmt.Printf("print %v\n", *token.AccessToken) // if refresh token happen this token will get changed
// prepare the IAM's Oauth 2.0 Extension service
oAuth20ExtensionService := &iam.OAuth20ExtensionService{
Client: factory.NewIamClient(&configRepo),
TokenRepository: &tokenRepo,
}
input := &o_auth2_0_extension.GetCountryLocationV3Params{}
// call an AccelByte Gaming Services API e.g. GetCountryLocationV3
ok, errLoc := oAuth20ExtensionService.GetCountryLocationV3Short(input)
if errLoc != nil {
fmt.Println(errLoc.Error())
} else {
fmt.Printf("Country name: %s\n", *ok.CountryName)
}
time.Sleep(5 * time.Second)
}
}