# Token refresh does not work in \`auth0-spa-js\`

**URL:** <https://community.auth0.com/t/token-refresh-does-not-work-in-auth0-spa-js/86051>\
**Category:** Product Feedback\
**Tags:** sdk, javascript\
**Created:** [June 28, 2022, 9:42am UTC](https://community.auth0.com/t/token-refresh-does-not-work-in-auth0-spa-js/86051 "2022-06-28T09:42:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ivk/32/34158_2.png) [@ivk](https://community.auth0.com/u/ivk)\
**Post date:** [June 28, 2022, 9:42am UTC](https://community.auth0.com/t/token-refresh-does-not-work-in-auth0-spa-js/86051/1 "2022-06-28T09:42:25Z")

</div>

**Issue:**  
Token refresh does not work in `auth0-spa-js`

**Description:**  
The `auth0-spa-js` can be configured to refresh tokens (`useRefreshTokens` flag).  
When an access token is expired `getTokenSilently()` tries to refresh it automatically.  
But `getTokenSilently()` does not pass `scope` to the `/token` endpoint.  
As a result, an ID token is not returned back and the “`ID token is required but missing` ” error is thrown.

**Use-case:**

1. Create a SPA with an automatic token refresh (`useRefreshTokens`) as explained in the Getting Started section:  
[@auth0/auth0-spa-js - npm](https://www.npmjs.com/package/@auth0/auth0-spa-js)
2. Decrease lifetime of ID or access token to 70 seconds on [https://manage.auth0.com](https://manage.auth0.com).
3. Open SPA and wait for 11 seconds (till the token is expired).
4. Call `getTokenSilently()` function.

Actual result: The “`ID token is required but missing` ” error is thrown.

Expected result: The tokes are refreshed.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 18, 2022, 10:08am UTC](https://community.auth0.com/t/token-refresh-does-not-work-in-auth0-spa-js/86051/2 "2022-07-18T10:08:29Z")

</div>

Hey there!

Thanks for creating this feedback card however the most effective way to handle that would be to raise a GitHub issue in the auth0-spa-js repo so we can work on that directly with the repo maintainers. Can you do that and then share a link to it here so we can ping them? Thank you!

---

<div class="post-metadata">

**Author:** ![ivk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ivk/32/34158_2.png) [@ivk](https://community.auth0.com/u/ivk)\
**Post date:** [July 18, 2022, 12:58pm UTC](https://community.auth0.com/t/token-refresh-does-not-work-in-auth0-spa-js/86051/3 "2022-07-18T12:58:07Z")

</div>

Thank you for letting me know!

I was asked to report it as feedback in support ticket that I created earlier:

> Also, you may consider leaving us product feedback about this: [Auth0: Secure access for everyone. But not just anyone.](https://auth0.com/feedback) Any feedback reported through that channel goes directly to our product team in order to help them prioritize future work.

> **[Auth0 Support Center](https://support.auth0.com/tickets/00759080)**
>
> Auth0 Support Center

Here is the created GitHub issue:

> <https://github.com/auth0/auth0-spa-js/issues/931>
>
> \### Describe the problem
> 
> The \`auth0-spa-js\` can be configured to refresh toke…ns (\`useRefreshTokens\` flag).
> When an access token is expired \`getTokenSilently()\` tries to refresh it automatically.
> But \`getTokenSilently()\` does not pass scope to the \`/token\` endpoint.
> As a result, an ID token is not returned back and the “\`ID token is required but missing\`” error is thrown.
> 
> \### Reproduction
> 
> 1. Create a SPA with an automatic token refresh (\`useRefreshTokens\`) as explained in the Getting Started section:
> \[@auth0/auth0-spa-js - npm\](https://www.npmjs.com/package/@auth0/auth0-spa-js)
> 2. Decrease lifetime of ID or access token to 70 seconds on https://manage.auth0.com/.
> 3. Open SPA and wait for 11 seconds (till the token is expired).
> 4. Call \`getTokenSilently()\` function.
> 
> \*\*Actual result\*\*: The “\`ID token is required but missing\`” error is thrown.
> \*\*Expected result:\*\* The tokes are refreshed.
> 
> \### Environment
> 
> \- Version of \`auth0-spa-js\` used: \`https://cdn.auth0.com/js/auth0-spa-js/1.22/auth0-spa-js.production.js\`
> \- Which browsers have you tested in? Chrome.
> \- Which framework are you using, if applicable (Angular, React, etc): reproduced on both pure \`auth0-spa-js\` and React.
> \- Other modules/plugins/libraries that might be involved: no.

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 19, 2022, 12:51pm UTC](https://community.auth0.com/t/token-refresh-does-not-work-in-auth0-spa-js/86051/4 "2022-07-19T12:51:38Z")

</div>

Perfect, thanks a lot for doing that!
