# How do refresh token works in auth0 angular12 using auth0/auth0-angular?

**URL:** <https://community.auth0.com/t/how-do-refresh-token-works-in-auth0-angular12-using-auth0-auth0-angular/70984>\
**Category:** Get Help\
**Tags:** token, refresh-tokens, auth0\
**Created:** [October 8, 2021, 7:15am UTC](https://community.auth0.com/t/how-do-refresh-token-works-in-auth0-angular12-using-auth0-auth0-angular/70984 "2021-10-08T07:15:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ifour.purvi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ifour.purvi/32/25292_2.png) [@ifour.purvi](https://community.auth0.com/u/ifour.purvi)\
**Post date:** [October 8, 2021, 7:15am UTC](https://community.auth0.com/t/how-do-refresh-token-works-in-auth0-angular12-using-auth0-auth0-angular/70984/1 "2021-10-08T07:15:37Z")

</div>

Hi,  
I’m trying to use refreshed token for calling the backend API when existing token gets expired  
with auth0 in angular12 SPA, But i’m not finding any proper explanation in any documentation.

I’ve tried calling getTokenSilently() method which resulting the Token, but i’m not sure that is that a correct one or not as i’m still recieveing 401!  
I am completely lost with it, should i’ve to call getIdTokenClaims again ?, or i’ve to use token returned by method getTokenSilently() ?  
or i’ve to use token returned by method getTokenSilently() to get the access token ?

Here is my configuration of auth0 as per the documentation of Refresh Token.

```auto
AuthModule.forRoot({
      domain: environment.auth0_client_domain,
      clientId: environment.auth0_client_id,
      audience: `${environment.audience}`,
      useRefreshTokens: true,
      httpInterceptor: {
        allowedList: [`${environment.serverUrl}/*`],
    }
}),

```

Here also, i’ve modified all the settings in auth0 dashboard as per the [documentation](https://auth0.com/docs/security/tokens/refresh-tokens/use-refresh-token-rotation?_ga=2.47134247.1632368468.1633433011-1478926330.1558960719&_gl=1*7qpypo*rollup_ga*MTQ3ODkyNjMzMC4xNTU4OTYwNzE5*rollup_ga_F1G3E656YZ*MTYzMzY3MzQzNC4xMDEuMS4xNjMzNjc2MDAwLjM2)

 ![API settings](https://global.discourse-cdn.com/auth0/original/3X/a/0/a0f9421a985e1db0011e5497d6af3418aa8fec00.png)  
 ![enable-refresh-token-rotation](https://global.discourse-cdn.com/auth0/original/3X/5/9/59d52a9be19514137754b256f8522738a798aca9.png)

Additionally , i’ve set ID Token Expiration to 60 sec, but i’m still able to use that token for longer, so is there anything missing?

 ![image](https://global.discourse-cdn.com/auth0/original/3X/f/7/f7f3a4800d3e56efd79024456a000469535d1a03.png)

Regards,  
Purvi.

---

<div class="post-metadata">

**Author:** ![Jaydeeps03](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jaydeeps03/32/36419_2.png) [@Jaydeeps03](https://community.auth0.com/u/Jaydeeps03)\
**Post date:** [January 13, 2023, 9:33am UTC](https://community.auth0.com/t/how-do-refresh-token-works-in-auth0-angular12-using-auth0-auth0-angular/70984/2 "2023-01-13T09:33:41Z")

</div>

Any update on this thread?

---

<div class="post-metadata">

**Author:** ![emrose11](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/emrose11/32/72254_2.png) [@emrose11](https://community.auth0.com/u/emrose11)\
**Post date:** [March 15, 2024, 9:19pm UTC](https://community.auth0.com/t/how-do-refresh-token-works-in-auth0-angular12-using-auth0-auth0-angular/70984/3 "2024-03-15T21:19:41Z")

</div>

Having the same issue, any updates or documentation on how refresh token for angular ?

---

<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:** [March 16, 2024, 12:31am UTC](https://community.auth0.com/t/how-do-refresh-token-works-in-auth0-angular12-using-auth0-auth0-angular/70984/5 "2024-03-16T00:31:45Z")

</div>

Hey there @emrose11 welcome to the community!

There are 3 things you need to do to enable your Angular app to use refresh tokens:

- Be sure the [registered API](https://auth0.com/docs/get-started/auth0-overview/set-up-apis) for which you are passing the identifier as the [audience param](https://community.auth0.com/t/what-is-the-audience/71414) has “Allow Offline Access” enabled in the API’s settings in your dashboard. In the sample application you set the audience param in [auth\_config.json](https://github.com/tyfrth/auth0-angular-samples/blob/ef5a539bcbd122a0f2b4d44466c993dc37c8182a/Sample-01/auth_config.json.example#L5).

- Turn on [refresh token rotation](https://auth0.com/docs/secure/tokens/refresh-tokens/configure-refresh-token-rotation) for the relevant SPA application in your dashboard.

- Set `useRefreshTokens: true` in your [AuthConfig](https://auth0.github.io/auth0-angular/interfaces/AuthConfig.html#useRefreshTokens). Here’s a working [example app](https://github.com/tyfrth/auth0-angular-samples/blob/ef5a539bcbd122a0f2b4d44466c993dc37c8182a/Sample-01/src/app/app.module.ts#L44). If you’d like to test, go to [/sample-01](https://github.com/tyfrth/auth0-angular-samples/tree/main/Sample-01) and follow the steps to get it up and running in your environment.

For testing purposes I recommend setting a short lived access token lifetime in your API settings. With the app up and running, log in, wait until the access token has expired (60 seconds for example), navigate to the “external api” page, and click “ping api”. Assuming your access token has expired, this will kick off a refresh token exchange using the stored refresh token. You can verify this is all successful by navigating to _monitoring → logs_ and looking for a successful refresh token exchange.

---

<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 30, 2024, 12:31am UTC](https://community.auth0.com/t/how-do-refresh-token-works-in-auth0-angular12-using-auth0-auth0-angular/70984/6 "2024-03-30T00:31:53Z")

</div>

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