# Query about invoking gettiingaccessTokenSilently() with limited scopes

**URL:** <https://community.auth0.com/t/query-about-invoking-gettiingaccesstokensilently-with-limited-scopes/61165>\
**Category:** Get Help\
**Tags:** jwt, auth0\
**Created:** [April 15, 2021, 2:16pm UTC](https://community.auth0.com/t/query-about-invoking-gettiingaccesstokensilently-with-limited-scopes/61165 "2021-04-15T14:16:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![praskatti](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/praskatti/32/13390_2.png) [@praskatti](https://community.auth0.com/u/praskatti)\
**Post date:** [April 15, 2021, 2:16pm UTC](https://community.auth0.com/t/query-about-invoking-gettiingaccesstokensilently-with-limited-scopes/61165/1 "2021-04-15T14:16:51Z")

</div>

Hi Auth0 Team,

I have a react app that makes remote api calls. all are running on my laptop. I have an set up and api on auth0 with multiple permissions. Let’s call them p1 and p2 for the sake of this discussion. When I want to invoke an endpoint on my backend that requires only p1, can I invoke getAccessTokenSilently with a scope of ‘p1’? In fact, I did so and the token still had both p1 and p2 in the scope. I was expecting it to have ‘p1’ only. since security is all about principle of least privilege. Am I missing something here? was I wrong to expect only P1 to show up in the token in the first place? BTW, I am not running into consent related issue here. something that was discussed in this thread.

> [@How to getTokenSilently without consent on localhost](https://community.auth0.com/t/how-to-gettokensilently-without-consent-on-localhost/39183/5):
>
> Regarding callback URLs: is your question referring to the fragment URLs (# part in there)? The fragments are not needed. Just https://local-api:5000/ should be enough for example. Sorry I might not have been clear. I mean if we need to remove any reference to localhost as the documentation you referenced mentioned: http://localhost:3000, https://local-api:3000 VS https://local-api:3000 in reference to: Similarly, you cannot skip consent (even for first-party applications) if local…

thank you.  
Prasad

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [April 29, 2021, 4:24pm UTC](https://community.auth0.com/t/query-about-invoking-gettiingaccesstokensilently-with-limited-scopes/61165/3 "2021-04-29T16:24:30Z")

</div>

Hi Prasad,

Could you please share some code snippets showing your Provider setup and getAccessTokenSilently invocation? Please redact anything sensitive before sharing it here

---

<div class="post-metadata">

**Author:** ![praskatti](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/praskatti/32/13390_2.png) [@praskatti](https://community.auth0.com/u/praskatti)\
**Post date:** [May 3, 2021, 6:42pm UTC](https://community.auth0.com/t/query-about-invoking-gettiingaccesstokensilently-with-limited-scopes/61165/4 "2021-05-03T18:42:18Z")

</div>

Hi Steve,

here’s the snippet of the code I tried using unsuccessfully:

# == const token = await getAccessTokenSilently( { audience, scope: “view:order” } );

==  
\<Auth0Provider  
domain={domain}  
clientId={client\_id}  
audience={audience}  
redirectUri={window.location.origin}

> 

```
  <App />

```

,

==

The user has perrmissions to create:order, delete:order and view:order. However, for viewing the order, I wanted the token to have only “view:order” permissions, based purely on the principle of minimalism. Hope this helps. I dont have the code on github yet.

Thank you.  
Prasad

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [May 13, 2021, 3:33pm UTC](https://community.auth0.com/t/query-about-invoking-gettiingaccesstokensilently-with-limited-scopes/61165/5 "2021-05-13T15:33:04Z")

</div>

Hi @praskatti, are you referring to the permissions array within the token, or what scopes are present in the token?

If it’s the former, this is due to a toggle in the API settings, which will append the user’s full list of permissions regardless of the scopes requested. You can disable this and is mentioned here in point 3:

> **[Enable Role-Based Access Control for APIs](https://auth0.com/docs/get-started/apis/enable-role-based-access-control-for-apis)**
>
> Learn how to enable role-based access control (RBAC) for an API using the Auth0 Dashboard or the Management API.

If you mean the scopes returned in the token, any scopes you specify in the `getAccessTokenSilently` call will be appended to the set of scopes set in the `Auth0Provider`’s scope, which defaults to “openid profile email” if no scope is specified in the provider.

---

<div class="post-metadata">

**Author:** ![praskatti](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/praskatti/32/13390_2.png) [@praskatti](https://community.auth0.com/u/praskatti)\
**Post date:** [May 13, 2021, 4:40pm UTC](https://community.auth0.com/t/query-about-invoking-gettiingaccesstokensilently-with-limited-scopes/61165/6 "2021-05-13T16:40:26Z")

</div>

Thanks Steve, Will check and post an update.

---

<div class="post-metadata">

**Author:** ![praskatti](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/praskatti/32/13390_2.png) [@praskatti](https://community.auth0.com/u/praskatti)\
**Post date:** [May 18, 2021, 5:10am UTC](https://community.auth0.com/t/query-about-invoking-gettiingaccesstokensilently-with-limited-scopes/61165/7 "2021-05-18T05:10:01Z")

</div>

Steve,  
I went back make the changes as suggested by the post. however, could not get it working.

I tried to parse this particular suggestion:

# == . When RBAC is disabled, the default behavior is observed; an application can request any permission defined for the API, and the `scope` claim will include all requested permissions

It does not include the permissions in the scope. Is there some working version of this on the github?

thank you.  
Prasad

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [May 18, 2021, 3:08pm UTC](https://community.auth0.com/t/query-about-invoking-gettiingaccesstokensilently-with-limited-scopes/61165/8 "2021-05-18T15:08:51Z")

</div>

Heya @praskatti , provided your user has had the permissions applied to their user account, directly or through roles that contain the required permissions, and you are specifying the correct audience for the scope’s parent API in your `/authorize` call it should be showing in the access token.  
The react app quickstart [here](https://auth0.com/docs/quickstart/spa/react/02-calling-an-api) shows a getAccessTokenSilently call in action and you can download the example from GitHub to try out against your own tenant and audience.

Please note though if you are trying to get scopes for the Management API, this is very limited for SPAs and only certain scopes can be requested:

> **[Get Management API Access Tokens for Single-Page Applications](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-tokens-for-single-page-applications)**
>
> Learn about available scopes and endpoints for Management API tokens for Single-page Applications (SPAs).

---

<div class="post-metadata">

**Author:** ![praskatti](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/praskatti/32/13390_2.png) [@praskatti](https://community.auth0.com/u/praskatti)\
**Post date:** [May 18, 2021, 4:49pm UTC](https://community.auth0.com/t/query-about-invoking-gettiingaccesstokensilently-with-limited-scopes/61165/9 "2021-05-18T16:49:42Z")

</div>

Hi Steve,  
Thank you. If I have a complex app and need to deal with fine grained permissions for my 50 odd micro services, will then have specify 50 scopes while using the Auth0Provider? surely there can be a more elegant way of handling this scenario.

thank you.

---

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [May 30, 2021, 9:03am UTC](https://community.auth0.com/t/query-about-invoking-gettiingaccesstokensilently-with-limited-scopes/61165/10 "2021-05-30T09:03:03Z")

</div>

Hi @praskatti ,

You’d want to set the commonly used scopes in the Auth0Provider, and add additional scopes as and when required using the getAccessTokenSilently to fetch new tokens with the relevant permissions.

There’s some previous community questions here on this topic which may help you:

- [What is the proper way to do fine-grained permissions? - #2 by Carlos\_Mostek](https://community.auth0.com/t/what-is-the-proper-way-to-do-fine-grained-permissions/11690/2)
- [Permissions/Roles Design Question - #2 by Carlos\_Mostek](https://community.auth0.com/t/permissions-roles-design-question/23490/2)

You may also want to review this blog article:

- [On The Nature of OAuth2’s Scopes](https://auth0.com/blog/on-the-nature-of-oauth2-scopes/)

---

<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:** [March 1, 2022, 12:13pm UTC](https://community.auth0.com/t/query-about-invoking-gettiingaccesstokensilently-with-limited-scopes/61165/11 "2022-03-01T12:13:13Z")

</div>

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