# Specifying scope before calling loginWithRedirect()

**URL:** <https://community.auth0.com/t/specifying-scope-before-calling-loginwithredirect/58521>\
**Category:** Get Help\
**Tags:** nodejs, react, scopes, auth0\
**Created:** [February 25, 2021, 4:10pm UTC](https://community.auth0.com/t/specifying-scope-before-calling-loginwithredirect/58521 "2021-02-25T16:10:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nwardcc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nwardcc/32/27809_2.png) [@nwardcc](https://community.auth0.com/u/nwardcc)\
**Post date:** [February 25, 2021, 4:10pm UTC](https://community.auth0.com/t/specifying-scope-before-calling-loginwithredirect/58521/1 "2021-02-25T16:10:16Z")

</div>

I have written a SPA using node react with a view to handling our client data within auth0.  
The app is working however to allow access to the metadata I am currently calling getAccessTokenSilently() with the scope set to read:current\_user and if that fails reverting to getAccessTokenWithPopup() with the same scope. This all works fine, however it’s a poor user experience for new users, who have to login/sign up and then separately grant access with another login popup enabling the required scope. Ideally I would prefer to specify the scope before calling loginWithRedirect(), is this possible?

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [February 25, 2021, 8:00pm UTC](https://community.auth0.com/t/specifying-scope-before-calling-loginwithredirect/58521/3 "2021-02-25T20:00:30Z")

</div>

Hi @nwardcc,

Welcome to the Community!

You can pass `scope` to `loginWithRedirect` so that the user grants access all at once:

```auto
loginWithRedirect({scope: 'read:current_user'})

```

---

<div class="post-metadata">

**Author:** ![nwardcc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nwardcc/32/27809_2.png) [@nwardcc](https://community.auth0.com/u/nwardcc)\
**Post date:** [February 26, 2021, 7:24am UTC](https://community.auth0.com/t/specifying-scope-before-calling-loginwithredirect/58521/4 "2021-02-26T07:24:57Z")

</div>

Hi Stephanie Thank you for you reply. You may have guessed but I am new to auth0! Is this documented anywhere, I couldn’t find any parms listed for this function? Also is it possible to pass in an array of scopes? Thanks again 🙂

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [February 26, 2021, 4:45pm UTC](https://community.auth0.com/t/specifying-scope-before-calling-loginwithredirect/58521/5 "2021-02-26T16:45:05Z")

</div>

No problem!

You can find all of the `loginWithRedirect` options in the auth0-react API reference: [https://auth0.github.io/auth0-react/interfaces/auth0\_context.redirectloginoptions.html](https://auth0.github.io/auth0-react/interfaces/auth0_context.redirectloginoptions.html)

To pass multiple scopes, you can separate each scope with a space in the string, like so:

```auto
loginWithRedirect({scope: "read:current_user create:current_user_metadata"})

```

---

<div class="post-metadata">

**Author:** ![nwardcc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nwardcc/32/27809_2.png) [@nwardcc](https://community.auth0.com/u/nwardcc)\
**Post date:** [March 1, 2021, 4:38pm UTC](https://community.auth0.com/t/specifying-scope-before-calling-loginwithredirect/58521/6 "2021-03-01T16:38:53Z")

</div>

Hi Sorry to be a pain, however I get the following when I make the suggested changes to the loginWithRedirect

react\_devtools\_backend.js:2430 The requested scopes (openid profile email read:user\_profile update:current\_user\_metadata) are different from the scopes of the retrieved token (openid profile email). This could mean that your access token may not include all the scopes that you expect. It is advised to resolve this by either:

- Removing `read:user_profile update:current_user_metadata` from the scope when requesting a new token.
- Ensuring `read:user_profile update:current_user_metadata` is returned as part of the requested token’s scopes.

Clearly I cannot take option one, so how do I ensure that this scope is returned as part of the requested token’s scopes.  
Thanks again

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [March 1, 2021, 4:51pm UTC](https://community.auth0.com/t/specifying-scope-before-calling-loginwithredirect/58521/7 "2021-03-01T16:51:06Z")

</div>

No problem at all!

Is the `audience` that you’re using in your app the Management API or is it an external API? If it is the Management API, instead of `read:user_profile`, can you use `read:current_user`?

Here are the scopes that are available to SPAs for the Management API: [https://auth0.com/docs/tokens/management-api-access-tokens/get-management-api-tokens-for-single-page-applications#available-scopes-and-endpoints](https://auth0.com/docs/tokens/management-api-access-tokens/get-management-api-tokens-for-single-page-applications#available-scopes-and-endpoints)

Also, can you send the code snippet for your `Auth0Provider` component?

For example:

```auto
ReactDOM.render(
  <Auth0Provider
    domain={config.domain}
    clientId={config.clientId}
    audience={config.audience}
    scope="openid profile email read:current_user update:current_user_metadata"
    redirectUri={window.location.origin}
    onRedirectCallback={onRedirectCallback}
    cacheLocation="localstorage"
    useRefreshTokens={true}
  >
    <App />
  </Auth0Provider>,
  document.getElementById("root")
);

```

---

<div class="post-metadata">

**Author:** ![nwardcc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nwardcc/32/27809_2.png) [@nwardcc](https://community.auth0.com/u/nwardcc)\
**Post date:** [March 1, 2021, 9:03pm UTC](https://community.auth0.com/t/specifying-scope-before-calling-loginwithredirect/58521/8 "2021-03-01T21:03:54Z")

</div>

Hi I was using the default setting from the example app, which passes null as the audience. It is now setup like this:  
{  
domain: config.domain,  
clientId: config.clientId,  
audience: `https://${config.domain}/api/v2/`,  
scope:“openid profile email read:current\_user update:current\_user\_metadata”,  
redirectUri: window.location.origin,  
onRedirectCallback,  
}  
which is working perfectly 🙂  
Thanks again for your help.

---

<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 16, 2021, 9:04pm UTC](https://community.auth0.com/t/specifying-scope-before-calling-loginwithredirect/58521/9 "2021-03-16T21:04:48Z")

</div>

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