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