Auth0 Home Blog Docs

Retrieving standard claims in idToken

claims
idtoken

#1

I want to retrieve standard claims from user meta data (gender, given name, family name) in the idToken. I’ve tried a few variations of rules with no success.

How can I accomplish this?


#2

If I understood you question correctly then using user.name = user.user_metadata.name; in a rule and doing a quick test showed it had the desired effect; the only issue was that I could not find any documentation for this exact approach so I’m unsure if doing this would be recommended.


function (user, context, callback) {
  user.name = user.user_metadata.name;
  user.gender = user.user_metadata.gender;
  
  callback(null, user, context);
}

#3

Can you post the entire code you used for the rule?

I guess I could apply user.gender = user.user_metadata.gender ?


#4

Can you post the entire code you used for the rule?

I guess I could apply user.gender = user.user_metadata.gender ?


#5

I will update the question with the full rule code, but what’s left is just the boilerplate stuff. I’ll also add a line for gender, but for standard claims it’s the same as name.


#6

Thanks for the code.

I’ve tried that but not getting the gender data through (I’m using lock10 on a noninteractive web page, requesting a token).

In terms of the rule, I copied and pasted what you provided and also tried some variations of the rule like so, but did not work.

context.accessToken [user.gender] = user.user_metadata.gender;

context.idToken [user.gender] = user.user_metadata.gender;

#7

Thanks for the code.

I’ve tried that but not getting the gender data through (I’m using lock10 on a noninteractive web page, requesting a token).

In terms of the rule, I copied and pasted what you provided and also tried some variations of the rule like so, but did not work.

context.accessToken [user.gender] = user.user_metadata.gender;

context.idToken [user.gender] = user.user_metadata.gender;

#8

What’s the type of value being stored in user.user_metadata.gender?


#9

This is the JSON that I have stored in meta data

  "gender": "male",
  "given_name": "John",
  "family_name": "Doe"

#10