# Add user email and roles in access token only for a specific app

**URL:** <https://community.auth0.com/t/add-user-email-and-roles-in-access-token-only-for-a-specific-app/115554>\
**Category:** Get Help\
**Tags:** classic-universal-login-experience, login-experience\
**Created:** [September 6, 2023, 3:24pm UTC](https://community.auth0.com/t/add-user-email-and-roles-in-access-token-only-for-a-specific-app/115554 "2023-09-06T15:24:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin.lescouarnec](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kevin.lescouarnec/32/50600_2.png) [@kevin.lescouarnec](https://community.auth0.com/u/kevin.lescouarnec)\
**Post date:** [September 6, 2023, 3:24pm UTC](https://community.auth0.com/t/add-user-email-and-roles-in-access-token-only-for-a-specific-app/115554/1 "2023-09-06T15:24:34Z")

</div>

Hello everyone 👋  
My company has a Auth0 organization with multiple applications in it.  
I would like to add user email and roles in the access token but only for a specific app. I added these fields with Auth0 Actions but it impacts all applications of the organization.  
How can I do that ?  
Thanks a lot for your help.

---

<div class="post-metadata">

**Author:** ![kevin.lescouarnec](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kevin.lescouarnec/32/50600_2.png) [@kevin.lescouarnec](https://community.auth0.com/u/kevin.lescouarnec)\
**Post date:** [September 26, 2023, 8:55pm UTC](https://community.auth0.com/t/add-user-email-and-roles-in-access-token-only-for-a-specific-app/115554/3 "2023-09-26T20:55:57Z")

</div>

There is no solution for this common use case ? 😬

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [September 26, 2023, 9:04pm UTC](https://community.auth0.com/t/add-user-email-and-roles-in-access-token-only-for-a-specific-app/115554/4 "2023-09-26T21:04:00Z")

</div>

Hey there @kevin.lescouarnec welcome to the community!

> [@kevin.lescouarnec](#):
>
> I would like to add user email and roles in the access token but only for a specific app. I added these fields with Auth0 Actions but it impacts all applications of the organization.

You should be able to do this by adding some logic to an [action](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow) to check for the application (`client_id`) and add the roles to the access token accordingly. It might look something like this:

```auto
exports.onExecutePostLogin = async (event, api) => {
  // Replace YOUR_CLIENT_ID with the actual Client ID of your specific application
  const targetClientId = 'YOUR_CLIENT_ID';
  
  if (event.client.clientID !== targetClientId) {
    // Not the target client, so we don't modify the token
    return;
  }
  
  const assignedRoles = event.authorization.roles;

  api.accessToken.setCustomClaim('http://namespace/roles', assignedRoles);
};

```

---

<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:** [October 10, 2023, 9:04pm UTC](https://community.auth0.com/t/add-user-email-and-roles-in-access-token-only-for-a-specific-app/115554/5 "2023-10-10T21:04:45Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
