# Add List user's organizations id and roles to the token

**URL:** <https://community.auth0.com/t/add-list-users-organizations-id-and-roles-to-the-token/83921>\
**Category:** Get Help\
**Created:** [May 23, 2022, 9:06am UTC](https://community.auth0.com/t/add-list-users-organizations-id-and-roles-to-the-token/83921 "2022-05-23T09:06:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![agustin.soler](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/agustin.soler/32/34401_2.png) [@agustin.soler](https://community.auth0.com/u/agustin.soler)\
**Post date:** [May 23, 2022, 9:06am UTC](https://community.auth0.com/t/add-list-users-organizations-id-and-roles-to-the-token/83921/1 "2022-05-23T09:06:42Z")

</div>

Hello!  
I’m trying to create a rule or something to add the list user’s organizations and it’s roles to the token…:  
for example the token would be something like this:

{  
“roles”: [  
“REGULAR”,  
“SUPERADMIN”  
],  
“iss”: “[https://example.eu.auth0.com/](https://example.eu.auth0.com/)”,  
“sub”: “auth0|000123123000”,  
“aud”: [  
“[https://example//api/v1/](https://example//api/v1/)”,  
“[https://example.eu.auth0.com/userinfo](https://example.eu.auth0.com/userinfo)”  
],  
“iat”: 1653295571,  
“exp”: 1653303631,  
“azp”: “cp2hivXUCzelTGKp4WQymFibf39GZs3O”,  
**"organizations: [{org1Id: 12345, roles:[“Regular-User, Admin”]}, {org2Id: 131231241, roles:["READER, SUPER ADMIN]}…]**

}

I hope you can help me!!

---

<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:** [May 23, 2022, 11:26pm UTC](https://community.auth0.com/t/add-list-users-organizations-id-and-roles-to-the-token/83921/3 "2022-05-23T23:26:52Z")

</div>

Hello there @agustin.soler !

Assuming a user is authorizing through an organization, the org\_id should be present in the ID/Access token(s) returned - Please see [this article](https://auth0.com/docs/manage-users/organizations/using-tokens) for more details.

Regarding roles specifically, we recommend setting up an [Action](https://auth0.com/docs/customize/actions#:~:text=Actions%20are%20secure%2C%20tenant%2Dspecific,Auth0's%20capabilities%20with%20custom%20logic.) to add these as a custom claim to tokens:

> [@Setting a user role in an action will not update the permissions in the access token](https://community.auth0.com/t/setting-a-user-role-in-an-action-will-not-update-the-permissions-in-the-access-token/70867/2):
>
> Hi @kl.auth Welcome to Auth0 Community !!! Don’t use Management API call for this. You can add a custom roles claim in a [post-login action](https://auth0.com/docs/actions/triggers/post-login) like this: /\*\* \* @param {Event} event - Details about the user and the context in which they are logging in. \* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login. \*/ exports.onExecutePostLogin = async (event, api) =\> { const namespace = 'https://my-app.example.com'; if (event.authorization) { api…

Hope this helps!

---

<div class="post-metadata">

**Author:** ![agustin.soler](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/agustin.soler/32/34401_2.png) [@agustin.soler](https://community.auth0.com/u/agustin.soler)\
**Post date:** [May 24, 2022, 10:54am UTC](https://community.auth0.com/t/add-list-users-organizations-id-and-roles-to-the-token/83921/4 "2022-05-24T10:54:40Z")

</div>

Hello @ty.frith thank you !

But with a “regular login” is there a way to get the list of all organizations that the user belongs and add it to the token like I askeb above?

**"organizations: [{org1Id: 12345, roles:[“Regular-User, Admin”]}, {org2Id: 131231241, roles:["READER, SUPER ADMIN]}…]**

---

<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:** [May 24, 2022, 10:11pm UTC](https://community.auth0.com/t/add-list-users-organizations-id-and-roles-to-the-token/83921/6 "2022-05-24T22:11:38Z")

</div>

Happy to help where I can!

> [@agustin.soler](#):
>
> But with a “regular login” is there a way to get the list of all organizations that the user belongs and add it to the token like I askeb above?

Without logging in within the context of an organization, I’m not aware of a way to add the Organizations to a user’s id/access token - You could always [poll the Management API](https://auth0.com/docs/api/management/v2#!/Users/get_user_organizations) for a list of Organizations the user is associated with, but again this would be outside the scope of a token.

---

<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:** [June 8, 2022, 10:12pm UTC](https://community.auth0.com/t/add-list-users-organizations-id-and-roles-to-the-token/83921/7 "2022-06-08T22:12:19Z")

</div>

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