# How to refresh a token before expiration

**URL:** <https://community.auth0.com/t/how-to-refresh-a-token-before-expiration/100738>\
**Category:** Get Help\
**Tags:** login-prompt-new-experience, login-experience\
**Created:** [February 17, 2023, 10:50am UTC](https://community.auth0.com/t/how-to-refresh-a-token-before-expiration/100738 "2023-02-17T10:50:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![laurent.thiebaud](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/laurent.thiebaud/32/44725_2.png) [@laurent.thiebaud](https://community.auth0.com/u/laurent.thiebaud)\
**Post date:** [February 17, 2023, 10:50am UTC](https://community.auth0.com/t/how-to-refresh-a-token-before-expiration/100738/1 "2023-02-17T10:50:52Z")

</div>

Hi,

I’d like to refresh an auth0 token before it expires. (for 2 reasons: not being disconnected + updating its content). Let’s every 2 hours whereas the token is valid during 2 days.  
From my understanding there are 2 ways:

- use a refresh token and call `/oauth/token` to refresh or token  
=\> I don’t like this solution because I’d have to store this refresh\_token in the browser which is not very secure  
=\> I tried with a “regular” token but couldn’t make it work (maybe I did a mistake and it should?)

- silent authentication by calling `/authorize` with `prompt=none`  
=\> in my application I’d need to do the call from a backend so it wouldn’t work (in my understanding in required the auth0 cookie session and)  
=\> I could do it from our frontend ; however on the SPA load, if the token is more than 2 hours, I’d need to do the round-trip to auth0 to refresh it (I’d like to avoid it)

Am I understanding well? Is there an endpoint where I could simply simply generate a new token from an existing one?

Thx

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [February 18, 2023, 2:06am UTC](https://community.auth0.com/t/how-to-refresh-a-token-before-expiration/100738/3 "2023-02-18T02:06:44Z")

</div>

Hi @laurent.thiebaud,

Welcome to the Auth0 Community!

> [@laurent.thiebaud](#):
>
> Am I understanding well? Is there an endpoint where I could simply simply generate a new token from an existing one?

Yes, you have the correct understanding! And yes, there is an endpoint to generate a new access token and it is through the `/oauth/token` endpoint which you have discovered. I recommend checking out our [Use Refresh Tokens](https://auth0.com/docs/secure/tokens/refresh-tokens/use-refresh-tokens) documentation if you experienced issues using your refresh token.

Next, silent authentication is another recommended approach, which you have also found.

> [@laurent.thiebaud](#):
>
> - if the token is more than 2 hours, I’d need to do the round-trip to auth0 to refresh it (I’d like to avoid it)

Yes, this is correct. In this case, I suggest using Refresh Tokens.

Please give it another try at [using refresh token](https://auth0.com/docs/secure/tokens/refresh-tokens/use-refresh-tokens) and let me know how it goes.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![laurent.thiebaud](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/laurent.thiebaud/32/44725_2.png) [@laurent.thiebaud](https://community.auth0.com/u/laurent.thiebaud)\
**Post date:** [February 20, 2023, 10:09am UTC](https://community.auth0.com/t/how-to-refresh-a-token-before-expiration/100738/4 "2023-02-20T10:09:06Z")

</div>

Hi thanks for your answer !

Concerning refresh tokens, I’d like to avoid to generate those. I read the documentation and if I understand well, 1/ it should be stored in the browser which I’d like to avoid as much as possible for security 2/ we have to handle the rotation and I’d like to keep our process as simple as possible.

So I’d like to call this /oauth/token endpoint but by providing a valid token only (and not a refresh token) - before it expires. I tested and it returns me this error:

```auto
{
    "error": "invalid_grant",
    "error_description": "Unknown or invalid refresh token."
}

```

I provided the params grant\_type, client\_id, refresh\_token,client\_secret, according to the doc.

So I guess it means it is only possible using a refresh token? In my understanding a refresh\_token was exactly the same as a usual token - only its use is different - so I’m probably wrong.

Thx

---

<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 6, 2023, 10:09am UTC](https://community.auth0.com/t/how-to-refresh-a-token-before-expiration/100738/5 "2023-03-06T10:09:27Z")

</div>

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