# How to include the username in the ID token

**URL:** <https://community.auth0.com/t/how-to-include-the-username-in-the-id-token/70142>\
**Category:** Get Help\
**Created:** [September 23, 2021, 10:19am UTC](https://community.auth0.com/t/how-to-include-the-username-in-the-id-token/70142 "2021-09-23T10:19:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rickh](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rickh/32/13599_2.png) [@rickh](https://community.auth0.com/u/rickh)\
**Post date:** [September 23, 2021, 10:19am UTC](https://community.auth0.com/t/how-to-include-the-username-in-the-id-token/70142/1 "2021-09-23T10:19:20Z")

</div>

I need to include the username field from the user in the ID token. I believe I need to set up a rule for this. I found an example on line;-

function (user, context, callback) {  
context.idToken[‘https://[my-tenant-domain]/username’] = user.username;  
return callback(null, user, context);  
}

But this seems to have no effect. Can this be done?

Thanks

---

<div class="post-metadata">

**Author:** ![rickh](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rickh/32/13599_2.png) [@rickh](https://community.auth0.com/u/rickh)\
**Post date:** [September 23, 2021, 11:01am UTC](https://community.auth0.com/t/how-to-include-the-username-in-the-id-token/70142/2 "2021-09-23T11:01:56Z")

</div>

Solved this myself;- You have to use a valid http or https namespace which is NOT your tenant name or any other Auth0 address.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [September 23, 2021, 11:14am UTC](https://community.auth0.com/t/how-to-include-the-username-in-the-id-token/70142/3 "2021-09-23T11:14:23Z")

</div>

Glad you have figured it out and thanks for sharing with the rest of community!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [September 30, 2021, 9:39am UTC](https://community.auth0.com/t/how-to-include-the-username-in-the-id-token/70142/4 "2021-09-30T09:39:40Z")

</div>


