【问题标题】:JWT token miss the claim in Nuxt Auth module with Auth0JWT 令牌使用 Auth0 错过 Nuxt Auth 模块中的声明
【发布时间】:2020-07-30 02:28:17
【问题描述】:

成功登录后,在我的 Nuxt 应用程序中,我收到了来自 Auth0 的声明。 Devtools 控制台显示它:

$vm0.$auth.$state.user['https://hasura.io/jwt/claims']
{x-hasura-default-role: "user", x-hasura-allowed-roles: Array(1), x-hasura-user-id: "auth0|5e989a*******"}

但我的令牌没有此声明,因此我的 hasura 请求失败。我在控制台中声明后立即检查令牌:

$vm0.$auth.getToken('auth0')
"Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Ik1ESTNNa0l5...

我使用https://jwt.io/ 对其进行解码并且没有任何声明:

{
"iss": "https://*******.eu.auth0.com/",
  "sub": "auth0|5e989a*******",
  "aud": [
    "https://*******.eu.auth0.com/api/v2/",
    "https://*******.eu.auth0.com/userinfo"
  ],
  "iat": 1587059738,
  "exp": 1587066938,
  "azp": "MxJB0Y9dxvdGZnTAb2a4Y0YOHArvbkWt",
  "scope": "openid profile email"
}

这是我在 Auth0 仪表板中的声明脚本:

function (user, context, callback) {
const namespace = "https://hasura.io/jwt/claims";
  context.idToken[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 nuxt.js auth0 hasura


    【解决方案1】:

    我通过更改 Auth0 仪表板中的声明脚本解决了这个问题。 它应该是 context.accessToken[namespace] = {...} 而不是 context.idToken[namespace] = {...},现在我的令牌中有该声明数据。

    【讨论】:

      猜你喜欢
      • 2019-09-22
      • 2021-04-21
      • 2019-09-12
      • 2019-05-10
      • 2021-04-30
      • 2020-06-01
      • 2019-08-08
      • 2020-10-23
      • 2016-12-23
      相关资源
      最近更新 更多