# Altering Access Token Scope/Permissions Per Organization

**URL:** <https://community.auth0.com/t/altering-access-token-scope-permissions-per-organization/68944>\
**Category:** Get Help\
**Tags:** jwt, rules\
**Created:** [September 1, 2021, 4:28pm UTC](https://community.auth0.com/t/altering-access-token-scope-permissions-per-organization/68944 "2021-09-01T16:28:48Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![calqulate](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/calqulate/32/19295_2.png) [@calqulate](https://community.auth0.com/u/calqulate)\
**Post date:** [September 1, 2021, 4:28pm UTC](https://community.auth0.com/t/altering-access-token-scope-permissions-per-organization/68944/1 "2021-09-01T16:28:48Z")

</div>

Hello,

My Auth0 users belong to multiple organizations in a classic multi-tenant context. For that reason, I need to modify access tokens generated at authentication time (using Rules/Hooks/Actions if necessary) to inject the correct `scope` claim in the access token.

The reason I do not want to use custom claims is because I need to use AWS HTTP API JWT Authorizers to validate the token automatically and restrict access to the called API according to the scope of the token.

Any ideas?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [September 2, 2021, 9:29pm UTC](https://community.auth0.com/t/altering-access-token-scope-permissions-per-organization/68944/3 "2021-09-02T21:29:03Z")

</div>

Hi @calqulate,

Welcome back!

~~Can you give an example of the changes you’d like to make to the token? It’s typically not possible to changes claims like _scope_ in the token via rules/hooks/actions/etc.~~

You can update the scopes directly in a rule.

---

<div class="post-metadata">

**Author:** ![calqulate](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/calqulate/32/19295_2.png) [@calqulate](https://community.auth0.com/u/calqulate)\
**Post date:** [September 3, 2021, 6:46pm UTC](https://community.auth0.com/t/altering-access-token-scope-permissions-per-organization/68944/4 "2021-09-03T18:46:16Z")

</div>

Hello @dan.woda,

Yes, sure! As I said in my question, the end result of token usage would be its validation by an AWS JWT Authorizer. The way this is done is by checking the token’s `scope` claim against the required scope of the lambda function being called.

The problem is that for our use case, a given user does not always have the same scope assigned to them; instead, that depends upon the “entity” they’re trying to fetch the token for. Imagine you as a user logging into an application, choosing to look at the data for Entity A; in that case you are an Admin. However, you may switch (refetch a new JWT token from Auth0) at any moment to look at data from Entity B, where you are just a Viewer.

I hope it’s clearer.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [September 8, 2021, 5:05pm UTC](https://community.auth0.com/t/altering-access-token-scope-permissions-per-organization/68944/5 "2021-09-08T17:05:10Z")

</div>

You aren’t able to update the `scopes` claim directly, like I mentioned. It is set based on the permissions assigned to the user either directly, or indirectly via [https://auth0.com/docs/authorization/rbac/](https://auth0.com/docs/authorization/rbac/). Is the entity the _resource_ you are trying to access? If it is, you may want to seperate them into different APIs/audiences and assigned roles based on each one.

For example, you could create an Entity A API and an Entity B API within Auth0, and assign a user an `Entity A - Admin` role and an `Entity B - Viewer` role, and they would have the respective permissions if you were requesting a token with either audience.

Would that make sense?

---

<div class="post-metadata">

**Author:** ![calqulate](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/calqulate/32/19295_2.png) [@calqulate](https://community.auth0.com/u/calqulate)\
**Post date:** [September 11, 2021, 9:18am UTC](https://community.auth0.com/t/altering-access-token-scope-permissions-per-organization/68944/6 "2021-09-11T09:18:27Z")

</div>

Thank you Dan, but no, the Entity is a company. It’s a simple multi-tenant context. The API (resource) is the same, but the user access privilege to the same API differs per Entity. I hope it’s clearer.

---

<div class="post-metadata">

**Author:** ![calqulate](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/calqulate/32/19295_2.png) [@calqulate](https://community.auth0.com/u/calqulate)\
**Post date:** [November 23, 2021, 10:02am UTC](https://community.auth0.com/t/altering-access-token-scope-permissions-per-organization/68944/7 "2021-11-23T10:02:55Z")

</div>

@dan.woda any updates on this please?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 23, 2021, 10:09pm UTC](https://community.auth0.com/t/altering-access-token-scope-permissions-per-organization/68944/8 "2021-11-23T22:09:15Z")

</div>

Hi @calqulate, sorry for the delay.

> [@calqulate](#):
>
> Imagine you as a user logging into an application, choosing to look at the data for Entity A; in that case you are an Admin. However, you may switch (refetch a new JWT token from Auth0) at any moment to look at data from Entity B, where you are just a Viewer.

Using Fake Co. as an example, you would have `entityA.fakeco.com/api` and `entityB.fakeco.com/api`. The token would have an audience for either entity, and scopes would be determined by which role the user is assigned for that audience.

---

<div class="post-metadata">

**Author:** ![calqulate](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/calqulate/32/19295_2.png) [@calqulate](https://community.auth0.com/u/calqulate)\
**Post date:** [November 24, 2021, 8:36am UTC](https://community.auth0.com/t/altering-access-token-scope-permissions-per-organization/68944/9 "2021-11-24T08:36:13Z")

</div>

Thank you @dan.woda but I think I’m unable to get my point across yet. Entity in our case is an organization. Users have a different role per organization. I can’t possibly create a different API audience per organization, can I? We have hundreds!

---

<div class="post-metadata">

**Author:** ![calqulate](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/calqulate/32/19295_2.png) [@calqulate](https://community.auth0.com/u/calqulate)\
**Post date:** [November 24, 2021, 8:47am UTC](https://community.auth0.com/t/altering-access-token-scope-permissions-per-organization/68944/10 "2021-11-24T08:47:06Z")

</div>

One more thing @dan.woda, reading here: [Auth0 Configuration (SPAs + API)](https://auth0.com/docs/architecture-scenarios/spa-api/part-2#configure-the-authorization-extension), it seems it is indeed possible to alter the scope! Where am I confused exactly?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 24, 2021, 4:51pm UTC](https://community.auth0.com/t/altering-access-token-scope-permissions-per-organization/68944/11 "2021-11-24T16:51:02Z")

</div>

> [@calqulate](#):
>
> One more thing @dan.woda, reading here: [Auth0 Configuration (SPAs + API)](https://auth0.com/docs/architecture-scenarios/spa-api/part-2?_ga=2.161836729.460826353.1637685201-1261373470.1602622721&_gl=1*xqrblx*rollup_ga*MTI2MTM3MzQ3MC4xNjAyNjIyNzIx*rollup_ga_F1G3E656YZ*MTYzNzc3MDg2Mi40MDEuMS4xNjM3NzcyMjE2LjE5#configure-the-authorization-extension), it seems it is indeed possible to alter the scope! Where am I confused exactly?

I was mistaken, you should be able to manipulate the scopes directly via a rule. Thanks for catching that, I’ll update my previous post.

---

<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:** [December 9, 2021, 4:52pm UTC](https://community.auth0.com/t/altering-access-token-scope-permissions-per-organization/68944/12 "2021-12-09T16:52:03Z")

</div>

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