# Retrieving standard claims in idToken

**URL:** <https://community.auth0.com/t/retrieving-standard-claims-in-idtoken/8093>\
**Category:** Get Help\
**Tags:** claims, idtoken\
**Created:** [September 5, 2017, 10:34pm UTC](https://community.auth0.com/t/retrieving-standard-claims-in-idtoken/8093 "2017-09-05T22:34:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidr1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/davidr1/32/10289_2.png) [@davidr1](https://community.auth0.com/u/davidr1)\
**Post date:** [September 5, 2017, 10:34pm UTC](https://community.auth0.com/t/retrieving-standard-claims-in-idtoken/8093/1 "2017-09-05T22:34:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [September 6, 2017, 6:07pm UTC](https://community.auth0.com/t/retrieving-standard-claims-in-idtoken/8093/2 "2017-09-06T18:07:48Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![davidr1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/davidr1/32/10289_2.png) [@davidr1](https://community.auth0.com/u/davidr1)\
**Post date:** [September 6, 2017, 7:45pm UTC](https://community.auth0.com/t/retrieving-standard-claims-in-idtoken/8093/3 "2017-09-06T19:45:16Z")

</div>

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

I guess I could apply user.gender = user.user\_metadata.gender ?

---

<div class="post-metadata">

**Author:** ![davidr1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/davidr1/32/10289_2.png) [@davidr1](https://community.auth0.com/u/davidr1)\
**Post date:** [September 6, 2017, 7:45pm UTC](https://community.auth0.com/t/retrieving-standard-claims-in-idtoken/8093/4 "2017-09-06T19:45:16Z")

</div>

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

I guess I could apply user.gender = user.user\_metadata.gender ?

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [September 7, 2017, 5:57pm UTC](https://community.auth0.com/t/retrieving-standard-claims-in-idtoken/8093/5 "2017-09-07T17:57:56Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![davidr1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/davidr1/32/10289_2.png) [@davidr1](https://community.auth0.com/u/davidr1)\
**Post date:** [September 7, 2017, 6:25pm UTC](https://community.auth0.com/t/retrieving-standard-claims-in-idtoken/8093/6 "2017-09-07T18:25:21Z")

</div>

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;

```

---

<div class="post-metadata">

**Author:** ![davidr1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/davidr1/32/10289_2.png) [@davidr1](https://community.auth0.com/u/davidr1)\
**Post date:** [September 7, 2017, 6:25pm UTC](https://community.auth0.com/t/retrieving-standard-claims-in-idtoken/8093/7 "2017-09-07T18:25:21Z")

</div>

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;

```

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [September 7, 2017, 6:55pm UTC](https://community.auth0.com/t/retrieving-standard-claims-in-idtoken/8093/8 "2017-09-07T18:55:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![davidr1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/davidr1/32/10289_2.png) [@davidr1](https://community.auth0.com/u/davidr1)\
**Post date:** [September 7, 2017, 10:32pm UTC](https://community.auth0.com/t/retrieving-standard-claims-in-idtoken/8093/9 "2017-09-07T22:32:51Z")

</div>

This is the JSON that I have stored in meta data

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

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:56am UTC](https://community.auth0.com/t/retrieving-standard-claims-in-idtoken/8093/10 "2018-03-02T05:56:20Z")

</div>


