# Change Sub Field in AccessToken

**URL:** <https://community.auth0.com/t/change-sub-field-in-accesstoken/9289>\
**Category:** Get Help\
**Tags:** api, access-token\
**Created:** [January 25, 2018, 4:43am UTC](https://community.auth0.com/t/change-sub-field-in-accesstoken/9289 "2018-01-25T04:43:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thlummail](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@thlummail](https://community.auth0.com/u/thlummail)\
**Post date:** [January 25, 2018, 4:43am UTC](https://community.auth0.com/t/change-sub-field-in-accesstoken/9289/1 "2018-01-25T04:43:41Z")

</div>

Right now I am trying to change the ‘sub’ field of my access token to the user’s email to match the pattern required by an API used in my app. Right now the code looks like

```
function (user, context, callback) {
  context.accessToken.sub = user.email;
  callback(null, user, context);
}

```

but when I examine the JWT, the sub field remains unchanged. What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![priya.sharma.9362](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/priya.sharma.9362/32/14302_2.png) [@priya.sharma.9362](https://community.auth0.com/u/priya.sharma.9362)\
**Post date:** [January 25, 2018, 2:09pm UTC](https://community.auth0.com/t/change-sub-field-in-accesstoken/9289/2 "2018-01-25T14:09:39Z")

</div>

Hi @thlummail

Perhaps the access\_tokens are not something to be parsed or modified by the client application, so if you want to have access to the email address in a browser-based application you should request that the email be included as part of the issued ID token (you can do that by making an OIDC request with scope containing openid and email.

Moreover, the “sub” claim refers to the id of the user to whom the token was granted.  
It would be better to configure your API to depend on the audience claim for granting access.

---

<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:** [July 25, 2019, 9:43am UTC](https://community.auth0.com/t/change-sub-field-in-accesstoken/9289/3 "2019-07-25T09:43:58Z")

</div>


