为什么我会收到错误消息"Error: GraphQL error: claims key: 'https://hasura.io/jwt/claims' not found"?



我在我的应用程序中使用 Auth0 进行身份验证和授权,并且我为 jwt 令牌指定了规则。但是我在控制台中收到此错误消息,"错误:GraphQL 错误:声明键:找不到'https://hasura.io/jwt/claims'"。 为什么?我可能错过了什么?

这是因为您的 JWT 令牌格式不正确。您的 JWT 令牌必须根据此处描述的 Hasura 规范进行格式化:

https://hasura.io/docs/1.0/graphql/manual/auth/authentication/jwt.html#the-spec

下面是一个示例:

{
"sub": "1234567890",
"name": "John Doe",
"admin": true,
"iat": 1516239022,
"https://hasura.io/jwt/claims": {
"x-hasura-allowed-roles": ["editor","user", "mod"],
"x-hasura-default-role": "user",
"x-hasura-user-id": "1234567890",
"x-hasura-org-id": "123",
"x-hasura-custom": "custom-value"
}
}

最新更新