-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvalidate_jwt_token.go
More file actions
50 lines (41 loc) · 1.55 KB
/
validate_jwt_token.go
File metadata and controls
50 lines (41 loc) · 1.55 KB
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
package authorizer
import "encoding/json"
type TokenType string
const (
// Token type access_token
TokenTypeAccessToken TokenType = "access_token"
// Token type id_token
TokenTypeIDToken TokenType = "id_token"
// Token type refresh_token
TokenTypeRefreshToken TokenType = "refresh_token"
)
// ValidateJWTTokenRequest defines attributes for validate_jwt_token request
type ValidateJWTTokenRequest struct {
TokenType TokenType `json:"token_type"`
Token string `json:"token"`
Roles []*string `json:"roles,omitempty"`
}
// ValidateJWTTokenInput is deprecated: Use ValidateJWTTokenRequest instead
type ValidateJWTTokenInput = ValidateJWTTokenRequest
// ValidateJWTTokenResponse defines attributes for validate_jwt_token response
type ValidateJWTTokenResponse struct {
IsValid bool `json:"is_valid"`
Claims map[string]interface{} `json:"claims"`
}
// ValidateJWTToken is method attached to AuthorizerClient.
// It performs validate_jwt_token query on authorizer instance.
// It returns ValidateJWTTokenResponse reference or error.
func (c *AuthorizerClient) ValidateJWTToken(req *ValidateJWTTokenRequest) (*ValidateJWTTokenResponse, error) {
bytesData, err := c.ExecuteGraphQL(&GraphQLRequest{
Query: `query validateJWTToken($data: ValidateJWTTokenRequest!){validate_jwt_token(params: $data) { is_valid claims } }`,
Variables: map[string]interface{}{
"data": req,
},
}, nil)
if err != nil {
return nil, err
}
var res map[string]*ValidateJWTTokenResponse
json.Unmarshal(bytesData, &res)
return res["validate_jwt_token"], nil
}