Add roles to access token

This has been a recurring topic, however none of the proposed solution worked for me.

  1. I created a role
  2. I assigned the role to my user.
  3. I created a custom rule as suggested here:
function addEmailToAccessToken(user, context, callback) {
  // This rule adds the authenticated user's roles to the access token.

  var namespace = 'https://my-url.us.auth0.com/';

  context.accessToken[namespace + 'roles'] = user.app_metadata.roles;
  return callback(null, user, context);
}

However user.app_metadata is undefined
Which should be the correct namespace?

Thanks to this topic I found the solution:

function (user, context, callback) {
    // This rule adds the authenticated user's roles to the access token.

  var namespace = 'https://my-domain.com/';
  context.accessToken[namespace + 'roles'] = context.authorization.roles;
  callback(null, user, context);
}

Thanks for posting an update @giovannilaperna!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.