<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-M74D8PB" height="0" width="0" style="display:none;visibility:hidden">
Loading
Skip to NavigationSkip to Main Content
Understanding Token Auto-Renewal in AuthJS
Okta Classic Engine
SDKs & Libraries
Overview
This article provides an explanation of how the auto-renewal feature of tokens operates in AuthJS. It is a vital feature that silently renews expired tokens, ensuring continued access to the service as long as there is a valid Okta session.
Applies To
Cause

When a token expires, the need for token renewal arises. If configured correctly, AuthJS auto-renews the expired token to maintain a smooth application flow.

Solution

Token auto-renewal in AuthJS is enabled by setting the autoRenew property to true in the AuthJS configuration. This action instructs the TokenManager to renew the expired token silently and fetch a valid token each time a request is made.

Example of AuthJS configuration:

var config = {
  url: 'https://{OktaDomainName}',
  tokenManager: {
    storage: 'sessionStorage',
    autoRenew: true
  }
};
var authClient = new OktaAuth(config);

When the token has expired, and a request is made to get the tokens (via TokenManager.get), AuthJS renews the expired token without prompting the user and retrieves a valid token.

NOTE: AuthJS previously featured an auto-refresh capability for tokens, but it was removed due to a potential race condition issue. In these instances, an expired token could be fetched if a refresh and token request occurred simultaneously. 

Loading
Understanding Token Auto-Renewal in AuthJS