# Auth0 spa 2.x returning missing\_refresh\_token

**URL:** <https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999>\
**Category:** Get Help\
**Tags:** refresh\_token, auth0\
**Created:** [January 26, 2023, 2:30am UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999 "2023-01-26T02:30:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mir](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mir/32/42844_2.png) [@mir](https://community.auth0.com/u/mir)\
**Post date:** [January 26, 2023, 2:30am UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/1 "2023-01-26T02:30:55Z")

</div>

I have been receiving errors when calling the `getTokenSilently()` method. The catch block receives `missing_refresh_token` and `login_required` error most of the times.

I have useRefreshToken enabled along with rotation enabled. Leeway 180 seconds.

Here is the code from my axios middleware

```auto
const auth0 = getInstance()

try {
      const accessToken = await auth0.getTokenSilently()
      // set axios headers
      config.headers.authorization = `Bearer ${accessToken}`
 } catch (err) {
  console.log(`axios err.error`, err.error)
  if (err.error === 'login_required') {
      window.location.href = auth0.loginWithRedirect()
  } else {
      // throw err
  }
}

```

Can anyone help identify why am I getting those two errors?

---

<div class="post-metadata">

**Author:** ![tridnguyen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tridnguyen/32/7005_2.png) [@tridnguyen](https://community.auth0.com/u/tridnguyen)\
**Post date:** [January 29, 2023, 9:51pm UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/2 "2023-01-29T21:51:44Z")

</div>

I use the react library with the new v2 version and I am getting missing\_refresh\_token errors for `getAccessTokenSilently` method as well.

---

<div class="post-metadata">

**Author:** ![finom](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/finom/32/44181_2.png) [@finom](https://community.auth0.com/u/finom)\
**Post date:** [January 31, 2023, 1:51pm UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/3 "2023-01-31T13:51:06Z")

</div>

Same issue after upgrading to v2.

---

<div class="post-metadata">

**Author:** ![mir](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mir/32/42844_2.png) [@mir](https://community.auth0.com/u/mir)\
**Post date:** [February 14, 2023, 4:24pm UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/4 "2023-02-14T16:24:42Z")

</div>

@auth0ops ? Any inputs here?

---

<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:** [February 14, 2023, 11:31pm UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/5 "2023-02-14T23:31:49Z")

</div>

Hi all! If the error is correct in that there is no refresh token available, I have hunch this may be related to the introduction of [authorizationParams](https://github.com/auth0/auth0-react/blob/master/MIGRATION_GUIDE.md#introduction-of-authorizationparams) and a missing `offline_access` scope in particular. The Auth0Provider in v2 should look like the following (note `scope` value in `authorizationParams`):

```auto
ReactDOM.render(
  <Auth0Provider
    domain="YOUR_AUTH0_DOMAIN"
    clientId="YOUR_AUTH0_CLIENT_ID"
    authorizationParams={{
      redirect_uri: window.location.origin,
      audience: "YOUR_AUDIENCE_ID",
      scope: "openid profile email offline_access"
    }}
  >
    <App />
  </Auth0Provider>,
  document.getElementById('app')
);

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![mir](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mir/32/42844_2.png) [@mir](https://community.auth0.com/u/mir)\
**Post date:** [February 15, 2023, 6:21pm UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/7 "2023-02-15T18:21:58Z")

</div>

@ty.frith @auth0ops by default the library is setting scope as `"openid profile email offline_access"`. Any other inputs?

---

<div class="post-metadata">

**Author:** ![dan-auth0](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@dan-auth0](https://community.auth0.com/u/dan-auth0)\
**Post date:** [February 16, 2023, 2:35am UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/8 "2023-02-16T02:35:40Z")

</div>

Howdy, 👋 `offline_access` is not set by defaullt:

> **[AuthorizationParams | @auth0/auth0-spa-js](https://auth0.github.io/auth0-spa-js/interfaces/AuthorizationParams.html#scope)**
>
> Documentation for @auth0/auth0-spa-js

If `authorizationParams.scope` is not set, the default value is `profile email`. The only scope that is always applied is `openid`.

---

<div class="post-metadata">

**Author:** ![mir](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mir/32/42844_2.png) [@mir](https://community.auth0.com/u/mir)\
**Post date:** [February 16, 2023, 4:12pm UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/9 "2023-02-16T16:12:45Z")

</div>

@dan-auth0 @auth0ops We have `useRefreshTokens` enabled. Which is why the `offline_access` is being appended.

> <https://github.com/auth0/auth0-spa-js/blob/master/src/Auth0Client.ts#L205>

We have rotation enabled in the auth0 tenant settings. I don’t think we are missing anything from our side. I have checked based on the documentation. But we are still getting `missing_refresh_token` error.

**Note:** We are using auth0-spa v2.

---

<div class="post-metadata">

**Author:** ![dan-auth0](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@dan-auth0](https://community.auth0.com/u/dan-auth0)\
**Post date:** [February 16, 2023, 4:21pm UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/10 "2023-02-16T16:21:16Z")

</div>

Gotcha! Thanks for adding that additional context 🙏

May I ask how you are reproducing this error locally to test it? I’d like to follow the same steps on one of our demos that uses the new SDK such as our Vue.js `v2` one:

> **[Vue.js Composition API Code Sample: Basic Authentication](https://developer.auth0.com/resources/code-samples/spa/vue/basic-authentication/v2-javascript)**
>
> This code sample uses Vue.js 3 with JavaScript and the Composition API to implement single-page application authentication using the Auth0 Vue SDK.

---

<div class="post-metadata">

**Author:** ![mir](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mir/32/42844_2.png) [@mir](https://community.auth0.com/u/mir)\
**Post date:** [February 17, 2023, 10:31pm UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/11 "2023-02-17T22:31:55Z")

</div>

@dan-auth0 Its happening locally as well as on test and prod tenants.

---

<div class="post-metadata">

**Author:** ![stackref-kmcduffee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stackref-kmcduffee/32/40913_2.png) [@stackref-kmcduffee](https://community.auth0.com/u/stackref-kmcduffee)\
**Post date:** [February 21, 2023, 4:28am UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/12 "2023-02-21T04:28:25Z")

</div>

I am also getting this error, even if setting scope and audience. Login still seems to work, but initial load of the page throws this error. Any other ideas @dan-auth0 ?

---

<div class="post-metadata">

**Author:** ![elig](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/elig/32/36250_2.png) [@elig](https://community.auth0.com/u/elig)\
**Post date:** [February 21, 2023, 4:41pm UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/13 "2023-02-21T16:41:00Z")

</div>

I have the same issue. It started after upgrading to v2.  
@dan-auth0 I think the severity of this issue should be raised. This is a serious problem and it affects all our users.

---

<div class="post-metadata">

**Author:** ![williamatslangdotai](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/williamatslangdotai/32/44811_2.png) [@williamatslangdotai](https://community.auth0.com/u/williamatslangdotai)\
**Post date:** [February 21, 2023, 5:06pm UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/14 "2023-02-21T17:06:12Z")

</div>

I wanted to add my voice to this being a big issue. We also experienced this when moving to v2.

I can see `offline_access` being passed as part of the scope in the authorize request but when refresh time comes around we get the `missing_refresh_token` error.

We are getting complaints from high profile customers in prod. Our workaround right now is to have them log out and log back in, but it looks really bad for our company.

---

<div class="post-metadata">

**Author:** ![dan-auth0](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@dan-auth0](https://community.auth0.com/u/dan-auth0)\
**Post date:** [February 21, 2023, 7:11pm UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/15 "2023-02-21T19:11:13Z")

</div>

Hello, all! Thanks for your feedback. Indeed, I am positioning this issue within the SDK team today 👍 I’ll keep you updated as information comes in. Thanks for all the details y’all are providing as that gives us solid context on where to look.

---

<div class="post-metadata">

**Author:** ![frederik.prijck](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/frederik.prijck/32/27014_2.png) [@frederik.prijck](https://community.auth0.com/u/frederik.prijck)\
**Post date:** [February 22, 2023, 7:40am UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/18 "2023-02-22T07:40:25Z")

</div>

Hello everyone!

I work at the SDK team on Auth0-SPA-JS, and will try to provide some information around whats happening.

Based on the information in the thread, I am not convinced this is a bug. But I am also not saying it can not be a bug, but we will need more information to know that.

But first, let me try and explain why this error shows up in v2, when it never showed up in v1.

**TDLR:**

Try and set `useRefreshTokensFallback` to true in v2 ([I have also updated our FAQ for this](https://github.com/auth0/auth0-spa-js/pull/1079)). If that does not restore behavior like you saw it with v1, please read the information below and reach out to us with more information through our [GitHub repository](https://github.com/auth0/auth0-spa-js).

**So what’s going on?**

Our SDK has two ways to retrieve a token:

- Using iframes, which relies on 3rd party cookies (unless using custom domains)
- Using refresh tokens

When using refresh tokens fails, we fall back to using an iframe based on the value of `useRefreshTokensFallback`. If it’s true, we try the iframe, if it’s false we throw “missing refresh token” in the event that we do not have a refresh token available. See [this check](https://github.com/auth0/auth0-spa-js/blob/master/src/Auth0Client.ts#L952) in our SDK.

[Based on the v2 migration guide](https://github.com/auth0/auth0-spa-js/blob/master/MIGRATION_GUIDE.md#no-more-iframe-fallback-by-default-when-using-refresh-tokens), you can see that we flipped the default value for `useRefreshTokensFallback` from true to false, this was done because more and more browsers are blocking third party cookies, and not everyone is using custom domains.

What this means if you never explicitly set `useRefreshTokensFallback`, you will suddenly start seeing `missing_refresh_token` error with v2, while it was swallowed with v1. This is not a bug, but a consequence of the change in the default value. (we might want to better call this out in the migratoin guide)

In a world where you are using refresh tokens without iframes fallback, when we do not have a refresh token available, there is nothing we can do but throw this error and ask you to call login again with the correct values.

If you would enable the useRefreshTokensFallback, it will get a token using an iframe as long as you have a valid active session with Auth0. If not, it will throw `login_required`.

**Reproducing the issue**

[I have updated our sample application](https://github.com/auth0-samples/auth0-javascript-samples/tree/example/missing-refresh-token) to reproduce this error in a couple of ways that are expected.

In the sample, you see 3 buttons:

- One calling getTokenSilently()
- One calling getTokenSilently({ authorizationParams: { scope: ‘scope-a’}})
- One calling getTokenSilently({ aughorizationParams: { audience: ‘Test’ }})

Both scope and audience are values that are not set when creating the Auth0Client or when calling loginWithRedirect.When the user is not logged in, calling all 3 of these methods throws `missing_refresh_token` , which is expected, as we have nothing in our cache.

When the user is logged in, we will get a set of tokens for the default audience and scope (so **not** for scope-a or audience Test). So when the user is logged in, clicking the first button works. However, the two other still throw the same `missing_refresh_token` error, as we have nothing in our cache for both scope=scope-a or audience=test. Which is still expected.

Clicking all of these buttons when useRefreshTokensFallback is set to true and there is still an active session with Auth0, will no longer throw the `missing_refresh_token` error but return tokens instead (or well, if the scope and audience are valid values for your tenant, if not you will get different errors, but no longer `missing_refresh_token`).

Hopefully this helps to provide some information about the behavior you are seeing with v2. If not, happy to try and assist further.

---

<div class="post-metadata">

**Author:** ![stackref-kmcduffee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stackref-kmcduffee/32/40913_2.png) [@stackref-kmcduffee](https://community.auth0.com/u/stackref-kmcduffee)\
**Post date:** [February 23, 2023, 12:44am UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/19 "2023-02-23T00:44:05Z")

</div>

Thank you @frederik.prijck ! I can confirm that setting `useRefreshTokensFallback: true` returns the previous behavior.

We are using custom domains, so would you say it’s still best practice NOT to use this setting and adapt appropriately?

---

<div class="post-metadata">

**Author:** ![frederik.prijck](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/frederik.prijck/32/27014_2.png) [@frederik.prijck](https://community.auth0.com/u/frederik.prijck)\
**Post date:** [February 23, 2023, 6:18am UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/20 "2023-02-23T06:18:13Z")

</div>

Hey @stackref-kmcduffee ,

When u use custom domains, settings this to true is definetly a good idea.

Just to be clear, there is nothing wrong in general with setting this to true, if it works better for your situation.

We disabled it by default because there are more and more situations where it doesnt work out of the box (without custom domains). So I would say there is nothing best practise about anything, it depends on your use-case.

But with custom domains, I would always turn it on myself.

---

<div class="post-metadata">

**Author:** ![serpil.acar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/serpil.acar/32/45055_2.png) [@serpil.acar](https://community.auth0.com/u/serpil.acar)\
**Post date:** [April 13, 2023, 3:50pm UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/21 "2023-04-13T15:50:52Z")

</div>

But what’s the solution then? Setting `useRefreshTokensFallback: true` doesn’t sound like a solution but a workaround. How to avoid `missing_refresh_token` error? You reproduced the issue for 3 different cases in your sample app but it would be nice if you added a working implementation as well. Do we need to include `scope` and `audience` when creating Auth0Client?

---

<div class="post-metadata">

**Author:** ![frederik.prijck](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/frederik.prijck/32/27014_2.png) [@frederik.prijck](https://community.auth0.com/u/frederik.prijck)\
**Post date:** [April 13, 2023, 4:17pm UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/22 "2023-04-13T16:17:28Z")

</div>

Hey @serpil.acar,

Enabling the fallback is the solution if you do not want to get MissingRefreshToken errors, and not a workaround.

I also didn’t reproduce any issue, it’s expected behavior for the SDK to have a missing Refresh Token when the fallback is not enabled. As mentioned, this fallback was enabled by default in v1, meaning you never got that error unless u explicitly disabled it. The only reason this error pops up in v2 and not in v1 is because of that, and not because of some bug. So setting it to true again restores behavior as in v1.

But as mentioned, getting a Missing Refresh Token is not a bug or an issue, but our SDK telling you it can not do what you want it to do because it has no refresh token and it can not acquire one.

You either have to enable the fallback, or call loginWithRedirect / loginWithPopup with the correct audience and scope.

Hopefully that helps.

---

<div class="post-metadata">

**Author:** ![serpil.acar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/serpil.acar/32/45055_2.png) [@serpil.acar](https://community.auth0.com/u/serpil.acar)\
**Post date:** [April 13, 2023, 5:07pm UTC](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999/23 "2023-04-13T17:07:30Z")

</div>

> You reproduced the issue for 3 different cases in your sample app but it would be nice if you added a working implementation as well.

Correction I meant you reproduced the “error” not the issue. Thank you for your answer.

That’s what I wanted to know, so I need to use correct audience and scope when calling loginWithRedirect method in order to get a refresh token. Anything else I should do? If it’s written in documentation, a link would be fine as well.

I’m still getting same error even though I use same audience&scope when creating Auth0Client and calling `loginWithRedirect` method with these. When I use `loginWithRedirect` with correct audience&scope, does SDK supposed to store refresh token and able to successfully use refresh token whenever I call `getTokenSilently` method?

[Next page](https://community.auth0.com/t/auth0-spa-2-x-returning-missing-refresh-token/98999.md?page=2)
