question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inactivity timeout is not respected when cacheLocation is localStorage

See original GitHub issue

Describe the problem When using localStorage and refresh tokens, inactivity timeout/ “require login after” (set in auth0 tenant settings -> advanced) does not cause auth0.isAuthenticated() to return false. The documentation around inactivity logouts is badly lacking, both for this SDK as well as on the auth0 doc pages. For example, I have no idea how the inactivity timeout is actually enforced (i assume via the expiration date on the auth0.isAuthenticated cookie?)

What was the expected behavior? When the inactivity timeout is reached, auth0.isAuthenticated() should return false. Or there should be some other documented means of checking if the timeout has been reached in order to redirect user to login page.
Access tokens should also be invalidated. The mechanism of inactivity timeout should also be documented somewhere (is it looking at the cookie expiration date? I have no idea because I couldn’t find docs)

Reproduction Set “inactivity timeout” and “require login after” to one minute in the auth0 dashboard for your tenant. Configure library with options { cacheLocation: ‘localstorage’, useRefreshTokens: true, …otherOptions } Add some arbitrary code that checks the return value of auth0.isAuthenticated(), for example:

 setInterval(() => {
    check();
  }, 30000);
}

async function check() {
  const auth0 = await configureClient();
  const isAuthed = await auth0.isAuthenticated();
  if (!isAuthed) {
    sessionLogout();
  }
}

Log in with any account. Wait more than one minute auth0.isAuthenticated() continues to return true

Rerun the same configuration, but with cacheLocation: memory auth0.isAuthenticated() returns false, as expected

Environment Using “@auth0/auth0-spa-js”: “^1.13.3” in a react application. Tested in a stable version of Chrome

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
nicosabenacommented, Dec 4, 2020

Auth0-spa-js, when you do getTokenSilently(), will try the refresh token flow first and if it doesn’t work then it will try to use the browser session (i.e. the session cookie) doing a fallback silent authentication request. This silent authentication request might fail because of a browser blocking the cookie in the request, but could also work well (and, in most scenarios, you’d want this to work, to spare the user from having to authenticate again). If that fails, the application might want to try an interactive authentication (with either a full redirection or a popup) and if the browser session is still valid then the user won’t be prompted to authenticate again. Which, again, is what you’d want under normal circumstances. If your use case require the user to re-authenticate after a period of inactivity, then you’ll need to coordinate the refresh token lifetime with the session lifetime. Otherwise the session will work as a fallback even when the refresh token is no longer valid.

Does that make sense?

1reaction
oneillsp96commented, Dec 2, 2020

Thanks for the quick responses. Overall I’m really enjoying the new SDK, and the fact that it handles refresh token rotation automatically is a huge benefit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Session not persisting using cacheLocation: localstorage
I have authentication with claims working except sessions are not persisting when refreshing the browser. I'm using auth0-spa-js with ...
Read more >
How to persist Auth0 login status in browser for React SPA
Instead, you can opt-in to store tokens in local storage by setting the cacheLocation property to localstorage when initializing the SDK.
Read more >
Persistent login in React using refresh token rotation
In this tutorial, you can learn how to use refresh tokens in React to facilitate infinitely long login sessions.
Read more >
react-aad-msal - npm Package Health Analysis - Snyk
Downloads are calculated as moving averages for a period of the last 12 months, excluding weekends and known missing data points. Maintenance. Inactive...
Read more >
Turbo for Windows Release Notes
Image downloads that took over an hour resulted in a timeout error when ... Installed applications no longer show the stopping session dialog...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found