Unable to create custom claim with special character in the claim name

I am trying to create an access token with a custom claim with a special character in the claim name(ex: user_email) but I see the generated token is not taking up the claim.

but I was successful with a special character(-), is this the expected behavior? character _(underscore) is not allowed?

action:

exports.onExecuteCredentialsExchange = async (event, api) => {
api.accessToken.setCustomClaim(“user_email”, (event.request.body.useremail || “”));

};

Hi @venkatasandeep.kolis,

Welcome to the Auth0 Community!

Yes! Appending custom claims with special characters like an underscore should work fine.

I did notice in your Action script that you are not using a namespaced URI to append your custom claims. This could lead to a scenario as you observed, where this claim is reserved and colliding an the existing claim. This causes your custom claim not to be added to your tokens.

(Reference: Create Custom Claims)

With that in mind, I recommend appending your custom claims using a namespaced URI. For example:

exports.onExecuteCredentialsExchange = async (event, api) => {
  api.accessToken.setCustomClaim("https://my-api.exampleco.com/user_email", (event.request.body.useremail || “”));
};

Please let me know how this goes for you.

Thanks,
Rueben

Thanks, Rueben for your response. But I even tried with ‘preferred_username’ and which is actually in the non-restricted category.

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