# 403 Forbidden Error when renewing token

**URL:** <https://community.auth0.com/t/403-forbidden-error-when-renewing-token/93187>\
**Category:** Get Help\
**Tags:** authorization-code-f, refresh\_token, auth0\
**Created:** [October 26, 2022, 11:50pm UTC](https://community.auth0.com/t/403-forbidden-error-when-renewing-token/93187 "2022-10-26T23:50:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![huzaifaali14](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/huzaifaali14/32/27739_2.png) [@huzaifaali14](https://community.auth0.com/u/huzaifaali14)\
**Post date:** [October 26, 2022, 11:50pm UTC](https://community.auth0.com/t/403-forbidden-error-when-renewing-token/93187/1 "2022-10-26T23:50:39Z")

</div>

I am facing 403 Forbidden error when I try to renew token. This error appears randomly and most of the time token gets renewed properly but sometimes I face this error. All my configuration including inactivity expiry and absolute expiry are set properly.

This is what my request looks like

````auto
        const formData = {
            grant_type: 'refresh_token',
            client_id,
            refresh_token: userSession?.refreshToken,
            client_secret
        };

        const formBody = Object.entries(formData)
            .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value as any)}`)
            .join('&');

        const tokenResponse = await fetch(`https://${config.AUTH0_DOMAIN}/oauth/token`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
            },
            body: formBody,
        });```

````

And this is the response I get when it results in error

(url=[https://dev-cdebase.auth0.com/oauth/token](https://dev-cdebase.auth0.com/oauth/token), status=403, statusText=Forbidden, ok=false, bodyUsed=true, size=0, timeout=0, \_abort=false, \_bytes=81)

```
--
headers: {
  "_headers": {
    "date": [
      "Wed, 26 Oct 2022 22:14:40 GMT"
    ],
    "content-type": [
      "application/json"
    ],
    "transfer-encoding": [
      "chunked"
    ],
    "connection": [
      "close"
    ],
    "cf-ray": [
      "76068bd50889b045-ATL"
    ],
    "cache-control": [
      "private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0, no-transform"
    ],
    "set-cookie": [
      "did=s%3Av0%3A95e67440-557b-11ed-bc3e-0dcfdb6ab38c.Mq47px2BL3noMvEstS94C%2FOfBl2B2WiOkCZ9qIdzKNc; Max-Age=31557600; Path=/; Expires=Fri, 27 Oct 2023 04:14:40 GMT; HttpOnly; Secure; SameSite=None",
      "did_compat=s%3Av0%3A95e67440-557b-11ed-bc3e-0dcfdb6ab38c.Mq47px2BL3noMvEstS94C%2FOfBl2B2WiOkCZ9qIdzKNc; Max-Age=31557600; Path=/; Expires=Fri, 27 Oct 2023 04:14:40 GMT; HttpOnly; Secure"
    ],
    "strict-transport-security": [
      "max-age=31536000"
    ],
    "vary": [
      "Accept-Encoding, Origin"
    ],
    "cf-cache-status": [
      "DYNAMIC"
    ],
    "ot-baggage-auth0-request-id": [
      "76068bd50889b045"
    ],
    "ot-tracer-sampled": [
      "true"
    ],
    "ot-tracer-spanid": [
      "4349817c1649d715"
    ],
    "ot-tracer-traceid": [
      "228e3efc230c5bcb"
    ],
    "traceparent": [
      "00-0000000000000000228e3efc230c5bcb-4349817c1649d715-01"
    ],
    "tracestate": [
      "auth0-request-id=76068bd50889b045,auth0=true"
    ],
    "x-auth0-requestid": [
      "bdfa963110f29b286003"
    ],
    "x-content-type-options": [
      "nosniff"
    ],
    "x-ratelimit-limit": [
      "30"
    ],
    "x-ratelimit-remaining": [
      "29"
    ],
    "x-ratelimit-reset": [
      "1666822481"
    ],
    "server": [
      "cloudflare"
    ],
    "alt-svc": [
      "h3=\":443\"; ma=86400, h3-29=\":443\"; ma=86400"
    ]
  }
}
--

```

```auto

```

---

<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:** [October 28, 2022, 5:39pm UTC](https://community.auth0.com/t/403-forbidden-error-when-renewing-token/93187/3 "2022-10-28T17:39:15Z")

</div>

Hi @huzaifaali14,

Is it possible your refresh token is expired?

---

<div class="post-metadata">

**Author:** ![huzaifaali14](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/huzaifaali14/32/27739_2.png) [@huzaifaali14](https://community.auth0.com/u/huzaifaali14)\
**Post date:** [October 29, 2022, 11:57pm UTC](https://community.auth0.com/t/403-forbidden-error-when-renewing-token/93187/4 "2022-10-29T23:57:55Z")

</div>

Hi @dan.woda it shouldn’t be. Its set to expire after almost 30 days.

 ![Screenshot 2022-10-30 at 4.57.07 AM](https://global.discourse-cdn.com/auth0/original/3X/1/9/192b2ea52bc498143592b66a8de882888067162c.png)

---

<div class="post-metadata">

**Author:** ![eterobby](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eterobby/32/12835_2.png) [@eterobby](https://community.auth0.com/u/eterobby)\
**Post date:** [October 31, 2022, 4:20pm UTC](https://community.auth0.com/t/403-forbidden-error-when-renewing-token/93187/5 "2022-10-31T16:20:53Z")

</div>

I would recommend to check the Monitoring → Logs in your Auth0 dashboard. You can search for specific event types using the dropdown, or I think you can use `type:fer*` to find all Failed Exchange of Refresh token errors (see [Log Event Type Codes](https://auth0.com/docs/deploy-monitor/logs/log-event-type-codes)).

The event type and description should provide more information to explain why you received an error. Based on what you’ve said, I would bet that the most likely scenario is that the refresh token was reused for some reason, e.g. because it is being reused across tabs or page views somehow.

---

<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:** [October 31, 2022, 9:31pm UTC](https://community.auth0.com/t/403-forbidden-error-when-renewing-token/93187/6 "2022-10-31T21:31:45Z")

</div>

Thanks for the help @eterobby!

---

<div class="post-metadata">

**Author:** ![mvas](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/mvas/32/40937_2.png) [@mvas](https://community.auth0.com/u/mvas)\
**Post date:** [October 31, 2022, 10:02pm UTC](https://community.auth0.com/t/403-forbidden-error-when-renewing-token/93187/7 "2022-10-31T22:02:14Z")

</div>

We still don’t know why and how the refresh token getting revoked. Giving bad experience to user as they need to login more often.

```auto
{
  "date": "2022-10-31T18:53:29.024Z",
  "type": "fertft",
  "description": "Unknown or invalid refresh token.",
  "connection_id": "",
  "client_id": "z75gKEQvfCmXiZE6vz3W2JRulfiAfh0L",
  "client_name": "xxxxxx",
  "ip": "35.227.66.34",
  "user_agent": "Other 0.0.0 / Other 0.0.0",
  "hostname": "clockbook.us.auth0.com",
  "user_id": "",
  "user_name": "",
  "log_id": "90020221031185332473273136468875951073554597710189822002",
  "_id": "90020221031185332473273136468875951073554597710189822002",
  "isMobile": false,
  "id": "90020221031185332473273136468875951073554597710189822002"
}

```

---

<div class="post-metadata">

**Author:** ![huzaifaali14](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/huzaifaali14/32/27739_2.png) [@huzaifaali14](https://community.auth0.com/u/huzaifaali14)\
**Post date:** [October 31, 2022, 10:28pm UTC](https://community.auth0.com/t/403-forbidden-error-when-renewing-token/93187/8 "2022-10-31T22:28:27Z")

</div>

hey @eterobby. I receive the below error always when this happen. And also I didn’t really get your point related to token being reused can you please elaborate? I want to add that I am having the same result whether with refresh token rotation on or off (reuse interval set to 1200 sec for testing). Seems to me the issue with Inactivity expiration( which is set correctly right now ) because I observed that If I leave the application for 10 12 hours it will throw the below error while renewing token. My Id token expiry is set to 2hrs which was done for testing this thing. It does renew token couple of time but eventually throws the 403 error.

 ![Screenshot 2022-11-01 at 3.22.25 AM](https://global.discourse-cdn.com/auth0/original/3X/7/3/73ef332926ddbf431b947fe71421ef71697692f4.png)

 ![Screenshot 2022-11-01 at 2.23.46 AM](https://global.discourse-cdn.com/auth0/original/3X/d/5/d5a3b997f8818be6ffb88156608aab6342a41f82.png)

---

<div class="post-metadata">

**Author:** ![eterobby](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eterobby/32/12835_2.png) [@eterobby](https://community.auth0.com/u/eterobby)\
**Post date:** [November 1, 2022, 2:42pm UTC](https://community.auth0.com/t/403-forbidden-error-when-renewing-token/93187/9 "2022-11-01T14:42:05Z")

</div>

The `Unknown or invalid refresh token` error message indicates that Auth0 is failing to recognize the refresh token for some reason, so either a valid token is not being transmitted somehow (in these circumstances, maybe you’re somehow sending garbage, or it’s missing or truncated or padded with extra characters or quotes) or a valid token is being transmitted but Auth0 is refused to recognize it (because it expired or was revoked).

It’s unclear to me from the context where this token is coming from, although the `Other 0.0.0` value for user agent suggests that you’re making this call from the server-side. The fact that you’re using `userSession?.refreshToken` suggests to me that `userSession` could be null/undefined in some circumstances, which would pass `"undefined"` as the token value and definitely lead to this type of error. I would highly recommend that you restructure this logic to check for a valid `userSession` and non-empty `refreshToken` and to throw your own error immediately rather than fruitlessly calling Auth0 with a missing token.

If you find that this error persists even after you are certain that the refresh token is non-empty (and presumably valid), then the only other thing that comes to mind is that somehow your refresh tokens are getting revoked, either through user logout or possibly you’re hitting the [200 maximum number of refresh tokens per user](https://auth0.com/docs/secure/tokens/refresh-tokens#limitations).

> And also I didn’t really get your point related to token being reused can you please elaborate? I want to add that I am having the same result whether with refresh token rotation on or off

I was specifically referring to refresh token rotation errors and that would have manifest with a different error and type (`ferrt`), so apparently that’s not your issue.

---

<div class="post-metadata">

**Author:** ![huzaifaali14](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/huzaifaali14/32/27739_2.png) [@huzaifaali14](https://community.auth0.com/u/huzaifaali14)\
**Post date:** [November 3, 2022, 7:37am UTC](https://community.auth0.com/t/403-forbidden-error-when-renewing-token/93187/10 "2022-11-03T07:37:05Z")

</div>

Hey @eterobby. The issue was actually in our code itself. So after renewing token we were updating information related to user session which in result was not storing the correct information and causing the failure on subsequent renew. I actually overlooked that issue. Now it’s working fine. Thank you very much for all the support and suggestions.

---

<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 7, 2022, 5:42pm UTC](https://community.auth0.com/t/403-forbidden-error-when-renewing-token/93187/11 "2022-11-07T17:42:13Z")

</div>

Thanks for following up @huzaifaali14!

---

<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:** [November 21, 2022, 5:43pm UTC](https://community.auth0.com/t/403-forbidden-error-when-renewing-token/93187/12 "2022-11-21T17:43:05Z")

</div>

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