Actions not setting claims/roles in JWT

Hello,

I have been trying for the past few days to get roles into the access token. To be fair, I am about to give up and move to a different provider because it seems to be so difficult, for such a simple thing.

I have tried every rule and action I have come across. I am using Authorization Core instead of the extension.

I have even tried to copy paste this action:

And it still doesn’t work.

I have tried setting dummy claims like this:

api.idToken.setCustomClaim('myClaim', 'this is a private, non namespaced claim');
api.accessToken.setCustomClaim('myClaim', 'this is a private, non namespaced claim');

And still no luck.

This is my current action:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://example.com';

  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
    api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
  }
};

I have also tried to follow this one:

I have also created an API and use that identity as audience during authorization but still no luck.

Best regards
Jarl

In case someone else stumbles upon this and are using nextauth along with the Auth0 provider.
You need to use the account.access_token property inside the jwt callback, to get the correct token instead of the id_token.

1 Like

Hi there @jarl-plateo welcome to the community!

Good to know you were able to resolve the issue and thanks a bunch for following up with your solution on this one - I’m sure it’ll be useful to someone moving forward :muscle: