What doesn't namespace refer to in this example?

In the following example taken from Auth0 docs what does the name space refer to, and how do I know what it is in my configuration/setup?

function (user, context, callback) {
  const namespace = 'http://demozero.net';
  const assignedRoles = (context.authorization || {}).roles;

  let idTokenClaims = context.idToken || {};
  let accessTokenClaims = context.accessToken || {};

  idTokenClaims[`${namespace}/roles`] = assignedRoles;
  accessTokenClaims[`${namespace}/roles`] = assignedRoles;

  context.idToken = idTokenClaims;
  context.accessToken = accessTokenClaims;

  callback(null, user, context);

Hi @brett2,

Using a namespace prevents custom claims from colliding with standard claims. The name space you use is up to you as long as you follow some specific guidelines. In short, it helps to differentiate the claims you are adding to the token versus the standard claims that are being added based on the spec.

This doc provides more information as well as the necessary guidelines:

Yeah, I see after using it it is a simply a name to use to customize the reference. It would be nice to have that in the docs, unless of corse I missed it (which is entirely possible).

Thank you Dan!

Glad that was helpful. The doc I linked should cover everything I just mentioned, is there some way it could be more helpful?

I guess the underlying issue is that from the reference of that example I don’t know what it’s doing and I didn’t see a reference on that page on were to figure out what it was for/didn’t know what to search for really. And I am a semi-experienced user of Auth0. Just not enough to remember all the pieces.

We are using this rule, and I was reviewing it. What I was seeing in my app vs. a client app wasn’t making sense, so I needed to find out.

Perhaps an output example of what the rule may be enough. Seeing how it was added to the identity token was all I needed to see to remember :slight_smile:


1 Like

Thanks for the feedback! I’ll pass it to our docs team.

1 Like

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