jwt - JWT 令牌使用 Auth0 错过 Nuxt Auth 模块中的声明
问题描述
成功登录后,在我的 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);
}
解决方案
我通过更改 Auth0 仪表板中的声明脚本解决了这个问题。它应该context.accessToken[namespace] = {...}
代替,context.idToken[namespace] = {...}
现在我的令牌中有该声明数据。
推荐阅读
- python - python - 遍历所有有间隙的连续项目对
- rust - 如何使用 Vec
作为返回类型并使用 wasm_bindgen 使其在 Javascript 中可读 - javascript - 找不到地图服务器中的 postgres db http://localhost/cgi-bin/LAYER157439308110272.png
- ios - 未定义符号:_getUnityPurchasingAppReceipt,在 xcode 上运行代码时出现此错误
- angular - Ionic 3 滑动滑轨
- quarkus - Hibernate Panache 更新多行查询
- python - M ↓ 在 Python 笔记本中是什么意思?
- asp.net-core-mvc - Can't generate proper anchor link in .net core 3.0
- google-apps-script - How to bundle a Slides add-on with an existing Docs add-on?
- intellij-idea - IntelliJ - Go back and forth in one split view only