Auth0 Home Blog Docs

Custom claim without namespace

i have this role in my roles

function (user, context, callback) {
  if(user.user_metadata){
    const namespace = 'https://mywebsite.com/';
    context.accessToken[namespace + 'role'] = user.user_metadata.role;
    context.idToken[namespace + 'role'] = user.user_metadata.role;
  }
  callback(null, user, context);
}

when i remove the name space it not work when i add it it work
how to remove name space and make it work
i need to get the role in the token

Removing the namespace from custom claims isn’t possible, because:

they must conform to a namespaced format to avoid possible collisions with standard OIDC claims.

(see https://auth0.com/docs/api-auth/tutorials/adoption/scope-custom-claims#custom-claims)

and roles, as opposed to the permissions claim when enabling RBAC core, aren’t available as root claims for access tokens (or ID tokens).

What’s the reason that you need the roles claim as root claim? Is it because the SDK you’re using to validate token and claims expects the roles to be exactly there, as root claims? Any additional context is helpful to understand your use case and need for this a bit better.

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