-
Notifications
You must be signed in to change notification settings - Fork 2
/
token.go
33 lines (30 loc) · 773 Bytes
/
token.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
package ringcentral
import (
"fmt"
"strings"
"time"
"github.com/grokify/oauth2more"
"github.com/grokify/oauth2more/credentials"
"golang.org/x/oauth2"
)
func NewTokenCli(creds credentials.Credentials, state string) (token *oauth2.Token, err error) {
if creds.OAuth2.IsGrantType(oauth2more.GrantTypeAuthorizationCode) {
state = strings.TrimSpace(state)
if len(state) == 0 {
state = "oauth2more-" + time.Now().UTC().Format(time.RFC3339)
}
fmt.Printf("OAuth State [%s]\n", state)
cfg := creds.OAuth2.Config()
token, err = oauth2more.NewTokenCliFromWeb(&cfg, state)
if err != nil {
return token, err
}
} else {
token, err = creds.NewToken()
if err != nil {
return token, err
}
}
token.Expiry = token.Expiry.UTC()
return token, nil
}