Setting autoRenew to true is not renewing the token automatically

“tokenManager”: {
“storage”: “localStorage”,
“autoRenew”: true,
“expireEarlySeconds”: 30
},

The above config does not seem to be working properly.

To verify whether autoRenew is working after enabling it in Okta. I tried simulating or observing a token nearing expiration and checking for its automatic renewal – but that doesn’t seem to be working.

The code below does not renew the token at all. What could be the issue?

const tokens = await oktaAuth.tokenManager.getTokens();
const accessToken = tokens.accessToken;

if(accessToken) {
  const expiredAccessToken = {
    ...accessToken,
    expiresAt: Math.floor(Date.now() / 1000) - 10
  }

  await oktaAuth.tokenManager.setTokens({
    ...tokens,
    accessToken: expiredAccessToken
  })

  console.log('Token artificially expired for testing autoRenew');
}
else {
  console.warn('No access token found.')
}

Versions here

@okta/okta-angular”: “^6.5.1”,
@okta/okta-auth-js”: “^7.12.1”,
@okta/okta-signin-widget”: “^7.30.3”,

Can you instead of forcing the token expiry, tryo check with shorter expiry of token using custom auth servers ? Autorenew is a service see docs here - GitHub - okta/okta-auth-js: The official js wrapper around Okta's auth API
That means the service decides if the renewal mechanism needs to be triggered. I would just test it under normal circumstances first.

2 Likes

Thanks for the reply!

@krishna How can I check if a service is running after invoking start method? And is there any way to dump the default configuration of a service?

Check / listen on for the events - see here okta-auth-js/lib/services/AutoRenewService.ts at b80f8bcb04529f5f107fecf379f7d93d84e960bc · okta/okta-auth-js · GitHub or check for isStarted method.

I tried a small example for tab inactivity, and even that doesn’t seem to renew the token even once. Can you share some links for reference with a complete example?

Thanks!

Try running our auth-js sample,

(static-spa sample has the exact thing you need - )

Listen on these events in the sample code if required.