IdentityModel / oidc-client-js

OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
Apache License 2.0
2.43k stars 842 forks source link

Question: Supporting a single renew that is shared across all tabs? #1344

Open justinbmeyer opened 3 years ago

justinbmeyer commented 3 years ago

If multiple tabs are using the same shared access/refresh token and one of the tabs starts renewing, can I prevent the other tabs from renewing and "piggy back" off the tab that is performing the renew?

Could https://developer.mozilla.org/en-US/docs/Web/API/Web_Locks_API be used in browsers that support it?

justinbmeyer commented 3 years ago

Any thoughts on this? I can work to submit a patch.

brockallen commented 3 years ago

The main issue is my bottleneck: If it's a complicated solution, then I don't have time to review.

justinbmeyer commented 3 years ago

Ideally, it should just be putting a web-lock around the code that makes the refresh:

navigator.locks.request('oidc-client-refresh', async lock => {
  await go_do_a_refresh();
});

And telling people to use the polyfill:

https://github.com/bitovi/web-locks-polyfill

Even better, we could feature detect if locks exists:

if(navigator.locks) {
  navigator.locks.request('oidc-client-refresh', async lock => {
   await go_do_a_refresh();
 });
} else {
   go_do_a_refresh();
}

This would allow people to still use oidc-client without the polyfill in browsers that are missing web-locks.