Merge pull request #285 from authorizerdev/development
feat(server): add jwt claims as part of validation endpoint
This commit is contained in:
commit
13edf1965c
|
@ -246,6 +246,7 @@ type ComplexityRoot struct {
|
|||
}
|
||||
|
||||
ValidateJWTTokenResponse struct {
|
||||
Claims func(childComplexity int) int
|
||||
IsValid func(childComplexity int) int
|
||||
}
|
||||
|
||||
|
@ -1646,6 +1647,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
|||
|
||||
return e.complexity.Users.Users(childComplexity), true
|
||||
|
||||
case "ValidateJWTTokenResponse.claims":
|
||||
if e.complexity.ValidateJWTTokenResponse.Claims == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.ValidateJWTTokenResponse.Claims(childComplexity), true
|
||||
|
||||
case "ValidateJWTTokenResponse.is_valid":
|
||||
if e.complexity.ValidateJWTTokenResponse.IsValid == nil {
|
||||
break
|
||||
|
@ -2110,6 +2118,7 @@ type Env {
|
|||
|
||||
type ValidateJWTTokenResponse {
|
||||
is_valid: Boolean!
|
||||
claims: Map
|
||||
}
|
||||
|
||||
type GenerateJWTKeysResponse {
|
||||
|
@ -9136,6 +9145,8 @@ func (ec *executionContext) fieldContext_Query_validate_jwt_token(ctx context.Co
|
|||
switch field.Name {
|
||||
case "is_valid":
|
||||
return ec.fieldContext_ValidateJWTTokenResponse_is_valid(ctx, field)
|
||||
case "claims":
|
||||
return ec.fieldContext_ValidateJWTTokenResponse_claims(ctx, field)
|
||||
}
|
||||
return nil, fmt.Errorf("no field named %q was found under type ValidateJWTTokenResponse", field.Name)
|
||||
},
|
||||
|
@ -10965,6 +10976,47 @@ func (ec *executionContext) fieldContext_ValidateJWTTokenResponse_is_valid(ctx c
|
|||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _ValidateJWTTokenResponse_claims(ctx context.Context, field graphql.CollectedField, obj *model.ValidateJWTTokenResponse) (ret graphql.Marshaler) {
|
||||
fc, err := ec.fieldContext_ValidateJWTTokenResponse_claims(ctx, field)
|
||||
if err != nil {
|
||||
return graphql.Null
|
||||
}
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.Claims, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(map[string]interface{})
|
||||
fc.Result = res
|
||||
return ec.marshalOMap2map(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) fieldContext_ValidateJWTTokenResponse_claims(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||
fc = &graphql.FieldContext{
|
||||
Object: "ValidateJWTTokenResponse",
|
||||
Field: field,
|
||||
IsMethod: false,
|
||||
IsResolver: false,
|
||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||
return nil, errors.New("field of type Map does not have child fields")
|
||||
},
|
||||
}
|
||||
return fc, nil
|
||||
}
|
||||
|
||||
func (ec *executionContext) _VerificationRequest_id(ctx context.Context, field graphql.CollectedField, obj *model.VerificationRequest) (ret graphql.Marshaler) {
|
||||
fc, err := ec.fieldContext_VerificationRequest_id(ctx, field)
|
||||
if err != nil {
|
||||
|
@ -17353,6 +17405,10 @@ func (ec *executionContext) _ValidateJWTTokenResponse(ctx context.Context, sel a
|
|||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "claims":
|
||||
|
||||
out.Values[i] = ec._ValidateJWTTokenResponse_claims(ctx, field, obj)
|
||||
|
||||
default:
|
||||
panic("unknown field " + strconv.Quote(field.Name))
|
||||
}
|
||||
|
|
|
@ -386,7 +386,8 @@ type ValidateJWTTokenInput struct {
|
|||
}
|
||||
|
||||
type ValidateJWTTokenResponse struct {
|
||||
IsValid bool `json:"is_valid"`
|
||||
IsValid bool `json:"is_valid"`
|
||||
Claims map[string]interface{} `json:"claims"`
|
||||
}
|
||||
|
||||
type VerificationRequest struct {
|
||||
|
|
|
@ -153,6 +153,7 @@ type Env {
|
|||
|
||||
type ValidateJWTTokenResponse {
|
||||
is_valid: Boolean!
|
||||
claims: Map
|
||||
}
|
||||
|
||||
type GenerateJWTKeysResponse {
|
||||
|
|
|
@ -93,5 +93,6 @@ func ValidateJwtTokenResolver(ctx context.Context, params model.ValidateJWTToken
|
|||
}
|
||||
return &model.ValidateJWTTokenResponse{
|
||||
IsValid: true,
|
||||
Claims: claims,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ func TestResolvers(t *testing.T) {
|
|||
|
||||
err := db.InitDB()
|
||||
if err != nil {
|
||||
t.Errorf("Error initializing database: %s", err.Error())
|
||||
t.Logf("Error initializing database: %s", err.Error())
|
||||
}
|
||||
|
||||
// clean the persisted config for test to use fresh config
|
||||
|
@ -71,14 +71,14 @@ func TestResolvers(t *testing.T) {
|
|||
envData.EnvData = ""
|
||||
_, err = db.Provider.UpdateEnv(ctx, envData)
|
||||
if err != nil {
|
||||
t.Errorf("Error updating env: %s", err.Error())
|
||||
t.Logf("Error updating env: %s", err.Error())
|
||||
}
|
||||
} else if err != nil {
|
||||
t.Errorf("Error getting env: %s", err.Error())
|
||||
t.Logf("Error getting env: %s", err.Error())
|
||||
}
|
||||
err = env.PersistEnv()
|
||||
if err != nil {
|
||||
t.Errorf("Error persisting env: %s", err.Error())
|
||||
t.Logf("Error persisting env: %s", err.Error())
|
||||
}
|
||||
|
||||
memorystore.Provider.UpdateEnvVariable(constants.EnvKeyEnv, "test")
|
||||
|
|
|
@ -93,5 +93,6 @@ func validateJwtTokenTest(t *testing.T, s TestSetup) {
|
|||
})
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, res.IsValid)
|
||||
assert.Equal(t, user.Email, res.Claims["email"])
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user