okta / okta-auth-js

The official js wrapper around Okta's auth API
Other
437 stars 255 forks source link

getTokens() - Add check to see if tokens are expired (or will in 30s) and try to refresh if so #1506

Closed coleleep closed 3 weeks ago

coleleep commented 2 months ago

Describe the feature request?

Add default behavior to perform a check to see if tokens are expired/expiring and perform a refresh if so. Currently getTokens() doesn't check for this.

We can write a method to do this but it would be idea if this was default behavior:

async function getAccessToken() {
  if (!(await oktaAuth.isAuthenticated()) {
    return null;
  }
  return oktaAuth.tokenManager.getTokens().accessToken;
}

New or Affected Resource(s)

getTokens();

Provide a documentation link

No response

Additional Information?

No response

jaredperreault-okta commented 3 weeks ago

https://github.com/okta/okta-auth-js?tab=readme-ov-file#getorrenewaccesstoken has been added