m.mikolajczak
m.mikolajczak

Reputation: 124

JWT token miss the claim in Nuxt Auth module with Auth0

In my Nuxt app after successful log in I have claim from Auth0. Devtools console shows it:

$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*******"}

But my token doesn't have this claim, so my hasura requests fails. I check token right after claim in console:

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

And I decode it using https://jwt.io/ and there is no claim:

{
"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"
}

Here is my claim script in Auth0 dashboard:

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);
}

Upvotes: 0

Views: 587

Answers (1)

m.mikolajczak
m.mikolajczak

Reputation: 124

I fixed this issue by changing claim script in Auth0 dashboard. It should be context.accessToken[namespace] = {...} instead of context.idToken[namespace] = {...} and now I have that claim data inside my token.

Upvotes: 1

Related Questions