# OKTA JWT Token is not automatically refreshed

**URL:** <https://devforum.okta.com/t/okta-jwt-token-is-not-automatically-refreshed/16164>\
**Category:** Questions\
**Tags:** angular\
**Created:** [September 16, 2021, 3:49am UTC](https://devforum.okta.com/t/okta-jwt-token-is-not-automatically-refreshed/16164 "2021-09-16T03:49:05Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sravan2478](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sravan2478](https://devforum.okta.com/u/sravan2478)\
**Post date:** [September 16, 2021, 3:49am UTC](https://devforum.okta.com/t/okta-jwt-token-is-not-automatically-refreshed/16164/1 "2021-09-16T03:49:05Z")

</div>

Hi,  
Am using OpenID with OAuth 2.0 with Angular as front end and .Net Core API as backend API.  
When am leaving my application idle for few hours and when am using my application again then my api calls are failing with unauthorized error. when I refresh the page everything works again. why is okta not refreshing the JWT token or at least automatically reload the page if the access token is expired? Please help me resolve this issue.

---

<div class="post-metadata">

**Author:** ![phi1ipp](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@phi1ipp](https://devforum.okta.com/u/phi1ipp)\
**Post date:** [September 17, 2021, 10:04pm UTC](https://devforum.okta.com/t/okta-jwt-token-is-not-automatically-refreshed/16164/2 "2021-09-17T22:04:55Z")

</div>

It depends on your implementation actually. Okta refreshes access token if properly configured.

---

<div class="post-metadata">

**Author:** ![sravan2478](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sravan2478](https://devforum.okta.com/u/sravan2478)\
**Post date:** [December 9, 2021, 2:27pm UTC](https://devforum.okta.com/t/okta-jwt-token-is-not-automatically-refreshed/16164/3 "2021-12-09T14:27:29Z")

</div>

Thanks for your response Philipp, below is how I implemented, please let me know what am missing. Okta is not refreshing token.

oktaConfig: {  
issuer: ‘’,  
clientId: ‘’,  
redirectUri: ‘[http://localhost:4200/login/callback’](http://localhost:4200/login/callback%E2%80%99),  
postLogoutRedirectUri: ‘[http://localhost:4200](http://localhost:4200/)’,  
scopes: [‘openid’, ‘profile’, ‘email’],  
pkce: true,  
tokenManager: { storage: ‘sessionStorage’}  
}

—app.module.ts—

providers: [  
{ provide: OKTA\_CONFIG, useValue: environment.oktaConfig }  
]

interceptor.ts----

constructor(private oktaAuth: OktaAuthService) { }

const accessToken = this.oktaAuth.getAccessToken();

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [December 9, 2021, 4:24pm UTC](https://devforum.okta.com/t/okta-jwt-token-is-not-automatically-refreshed/16164/4 "2021-12-09T16:24:04Z")

</div>

What page of your application are you on when the session expires? If you try to access a protected route or use a token in anyway, does the refresh occur then?

Also, I recommend enabling refresh tokens in your app (under Grant Types) and adding the `offline_access` scope to your config. This way you’re not dependent on the Okta session lifetime to refresh tokens for the user (which is also a potential complication).

---

<div class="post-metadata">

**Author:** ![sravan2478](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sravan2478](https://devforum.okta.com/u/sravan2478)\
**Post date:** [December 9, 2021, 4:39pm UTC](https://devforum.okta.com/t/okta-jwt-token-is-not-automatically-refreshed/16164/5 "2021-12-09T16:39:10Z")

</div>

Thanks for your reply Andrea.  
after 1 hour whenever my application makes api call then i will receive unauthorized error due to token expiry.  
I have added the scope offline\_access to the list scopes but still the session expires.  
scopes: [‘openid’, ‘profile’, ‘email’, ‘offline\_access’].  
Refresh token is enabled in app integration but implicit is not enabled, does this cause issue? please help me figure out what am missing.

---

<div class="post-metadata">

**Author:** ![sravan2478](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sravan2478](https://devforum.okta.com/u/sravan2478)\
**Post date:** [December 9, 2021, 4:39pm UTC](https://devforum.okta.com/t/okta-jwt-token-is-not-automatically-refreshed/16164/6 "2021-12-09T16:39:41Z")

</div>

am using angular at my SPA.

---

<div class="post-metadata">

**Author:** ![sravan2478](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sravan2478](https://devforum.okta.com/u/sravan2478)\
**Post date:** [December 9, 2021, 4:43pm UTC](https://devforum.okta.com/t/okta-jwt-token-is-not-automatically-refreshed/16164/7 "2021-12-09T16:43:08Z")

</div>

My protected Routes work fine after 1 hour but the JW token which am passing to my api calls is getting unauthorized. am using .net core api at my back end, below is how i implemented at backend  
startup.cs  
using Okta.AspNetCore;

services.AddAuthentication(options =\>  
{  
options.DefaultAuthenticateScheme = OktaDefaults.ApiAuthenticationScheme;  
options.DefaultChallengeScheme = OktaDefaults.ApiAuthenticationScheme;  
options.DefaultSignInScheme = OktaDefaults.ApiAuthenticationScheme;  
})

```
        .AddOktaWebApi(new OktaWebApiOptions()
        {
            OktaDomain = Configuration["Okta:OktaDomain"],
            AuthorizationServerId = Configuration["Okta:AuthorizationServerId"],
            Audience = Configuration["Okta:Audience"]
        });
        services.AddAuthorization();
```

---

<div class="post-metadata">

**Author:** ![bwilmott](https://avatars.discourse-cdn.com/v4/letter/b/90db22/32.png) [@bwilmott](https://devforum.okta.com/u/bwilmott)\
**Post date:** [March 14, 2023, 7:32pm UTC](https://devforum.okta.com/t/okta-jwt-token-is-not-automatically-refreshed/16164/8 "2023-03-14T19:32:35Z")

</div>

hello @andrea did you ever find a resolve for this. Having a similar issue, even with offline access scope being added.The accessToken is not being refreshed automatically

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [March 14, 2023, 9:01pm UTC](https://devforum.okta.com/t/okta-jwt-token-is-not-automatically-refreshed/16164/9 "2023-03-14T21:01:56Z")

</div>

Are you using our SDKs?

---

<div class="post-metadata">

**Author:** ![bwilmott](https://avatars.discourse-cdn.com/v4/letter/b/90db22/32.png) [@bwilmott](https://devforum.okta.com/u/bwilmott)\
**Post date:** [March 15, 2023, 9:41am UTC](https://devforum.okta.com/t/okta-jwt-token-is-not-automatically-refreshed/16164/10 "2023-03-15T09:41:57Z")

</div>

@andrea Yes we are using the refresh token option as well as offline\_access in the scope. Our application is using module federated microfrontend in Angular. we cannot seem to get a new token after the expiry even though we our receiving a refresh token. I was thinking okta would handle this on its own

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [March 15, 2023, 7:34pm UTC](https://devforum.okta.com/t/okta-jwt-token-is-not-automatically-refreshed/16164/11 "2023-03-15T19:34:43Z")

</div>

I didn’t see it mentioned, but does that mean you are using one of the packages Okta has for OIDC (either [AuthJS](https://github.com/okta/okta-auth-js) or our dedicated [Angular library](https://github.com/okta/okta-angular)), or are you using a third party library to handle the OIDC flow? If the latter, do you know if this library is able to handle token refreshes for you?

---

<div class="post-metadata">

**Author:** ![andrea](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/andrea/32/2172_2.png) [@andrea](https://devforum.okta.com/u/andrea)\
**Post date:** [February 13, 2024, 12:41am UTC](https://devforum.okta.com/t/okta-jwt-token-is-not-automatically-refreshed/16164/12 "2024-02-13T00:41:44Z")

</div>

Closed on February 13, 2024, 12:41am UTC


