Retrieving standard claims in idToken

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?

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);
}

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

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

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

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

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.

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;

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;

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

This is the JSON that I have stored in meta data

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