Understanding Okta AuthJS Token Auto-Renewal
Last Updated:
Overview
The auto-renewal feature in AuthJS silently renews expired tokens to ensure continued access to the service as long as a valid Okta session exists. Enabling the auto-renew property in the AuthJS configuration instructs the TokenManager to fetch a valid token automatically when the application makes a request.
Applies To
- AuthJS
- Okta Classic Engine
- Okta Identity Engine (OIE)
Cause
When a token expires, AuthJS requires token renewal. AuthJS auto-renews the expired token to maintain a smooth authentication flow when configured correctly.
Solution
How does token auto-renewal function in AuthJS?
Setting the autoRenew property to true in the AuthJS configuration enables token auto-renewal. This action instructs the TokenManager to renew the expired token silently and fetch a valid token each time the application makes a request.
Enable token auto-renewal by setting the auto-renew property to true within the AuthJS configuration block.
var config = {
url: 'https://{OktaDomainName}',
tokenManager: {
storage: 'sessionStorage',
autoRenew: true
}
};
var authClient = new OktaAuth(config);
When the token expires and the application requests the tokens via TokenManager.get, AuthJS renews the expired token without prompting the user and retrieves a valid token.
How is the passive token renewal strategy used?
Okta recommends using the new passive token renewal strategy described in the AuthJS Auto-Renew Notice.
NOTE: AuthJS previously featured an auto-refresh capability for tokens, but Okta removed it due to a potential race condition issue. In these instances, the application could fetch an expired token if a refresh and token request occurred simultaneously.
