Sign up for Hasura Newsletter
Loading...

自定义 JWT 声明规则

JWT 内的自定义声明用于向 Hasura 说明调用方的角色,以便 Hasura 实施必要的授权规则,以确定该调用方的权限。 在 Auth0 控制面板中,导航至规则

单击+ Create Rule按钮。 在下一个屏幕中,选择Empty rule模板。

将规则命名为hasura-jwt-claims

将以下脚本添加至规则中。

function (user, context, callback) {
const namespace = "https://hasura.io/jwt/claims";
context.accessToken[namespace] =
{
'x-hasura-default-role': 'user',
// do some custom logic to decide allowed roles
'x-hasura-allowed-roles': ['user'],
'x-hasura-user-id': user.user_id
};
callback(null, user, context);
}

自定义 JWT 声明规则

Did you find this page helpful?
Start with GraphQL on Hasura for Free
  • ArrowBuild apps and APIs 10x faster
  • ArrowBuilt-in authorization and caching
  • Arrow8x more performant than hand-rolled APIs
Promo
footer illustration
Brand logo
© 2024 Hasura Inc. All rights reserved
Github
Titter
Discord
Facebook
Instagram
Youtube
Linkedin