JWT令牌未通过Auth0在Nuxt Auth模块中声明
成功登录后,在我的Nuxt应用程序中,我已从Auth0获得声明。Devtools控制台显示:JWT令牌未通过Auth0在Nuxt Auth模块中声明,jwt,nuxt.js,auth0,hasura,Jwt,Nuxt.js,Auth0,Hasura,成功登录后,在我的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.$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...
我用密码破译了它,没有任何声明:
{
"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]={…}
,现在我的令牌中有了声明数据