Repository navigation
Expand file tree
/
Copy pathvalidate_jwt_token.go
More file actions
66 lines (58 loc) · 2.13 KB
/
Copy pathvalidate_jwt_token.go
File metadata and controls
66 lines (58 loc) · 2.13 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package authorizer
import (
"context"
"net/http"
authorizerv1 "github.com/authorizerdev/authorizer-proto-go/authorizer/v1"
"google.golang.org/protobuf/proto"
)
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) {
var res ValidateJWTTokenResponse
err := c.execute(methodSpec{
name: "ValidateJWTToken",
graphql: &GraphQLRequest{
Query: `query validateJWTToken($data: ValidateJWTTokenRequest!){validate_jwt_token(params: $data) { is_valid claims } }`,
Variables: map[string]interface{}{"data": req},
},
graphqlField: "validate_jwt_token",
restMethod: http.MethodPost,
restPath: "/v1/validate_jwt_token",
restBody: req,
restResp: func() proto.Message { return &authorizerv1.ValidateJwtTokenResponse{} },
grpcCall: func(ctx context.Context, cli authorizerv1.AuthorizerServiceClient) (interface{}, error) {
var in authorizerv1.ValidateJwtTokenRequest
if err := remarshal(req, &in); err != nil {
return nil, err
}
return cli.ValidateJwtToken(ctx, &in)
},
}, nil, &res)
if err != nil {
return nil, err
}
return &res, nil
}