-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_token.go
37 lines (30 loc) · 1.11 KB
/
get_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
34
35
36
37
package authorizer
import "errors"
// TokenQueryInput defines attributes for token request
type TokenQueryInput struct {
Code *string `json:"code"`
GrantType *string `json:"grant_type"`
RefreshToken *string `json:"refresh_token"`
}
// TODO check if we can use oauth get token from backend
// TokenResponse defines attributes for token request
type TokenResponse struct {
AccessToken string `json:"access_token"`
ExpiresIn int64 `json:"expires_in"`
IdToken string `json:"id_token"`
RefreshToken *string `json:"refresh_token"`
}
// GetToken is method attached to AuthorizerClient.
// It performs `/oauth/token` query on authorizer instance.
// It returns User reference or error.
// For implementation details check GetTokenExample examples/get_token.go
func (c *AuthorizerClient) GetToken(req *TokenQueryInput) (*TokenResponse, error) {
grantType := StringValue(req.GrantType)
if grantType == "" {
req.GrantType = NewStringRef(GrantTypeAuthorizationCode)
}
if grantType == GrantTypeRefreshToken && req.RefreshToken == nil {
return nil, errors.New("invalid refresh token")
}
return nil, nil
}