okta-auth-js icon indicating copy to clipboard operation
okta-auth-js copied to clipboard

Okta Auth in PWA with offline access

Open brvaland opened this issue 3 years ago • 4 comments

Hi,

I am building progressive web app with okta authentication, we do have a requirement that user should be able to continue accessing application once authenticated and have access token even if the token is expired.

As per okta-auth-js default storage is browser local storage and token is persisted even user close browser and come back but once token is expired it auto-renewed but if user is offline i would like auto renewal to be paused and user to be able to continue using the application.

Currently I am getting blank page on my application when user is offline and okta trying to renew the token.

Here is the link to demo application - https://codesandbox.io/s/unruffled-hill-4g4i5

brvaland avatar Apr 08 '21 17:04 brvaland

@brvaland I would recommend setting tokenManager.autoRenew and tokenManager.autoRemove to false in the tokenManager options and then subscribing to the expired event from the TokenManager. Your event handler can choose whether to renew the token immediately or defer for later.

aarongranick-okta avatar Apr 08 '21 17:04 aarongranick-okta

@aarongranick-okta - thanks for your quick reply.

I did configure as per your suggestion and token renewal stopped and allows me to differ it later and able to renew token once user is back online. I have noticed an issue when user is offline, token is expired and then user click on browser refresh or F5 app is redirected to okta and browser throws network error.

Here is link reference to what i have implemented - https://codesandbox.io/s/unruffled-hill-4g4i5?file=/src/AppRouter.tsx

Please advise ?

brvaland avatar Apr 09 '21 15:04 brvaland

@aarongranick-okta any update reference to the code example (link posted above).?

brvaland avatar Apr 20 '21 08:04 brvaland

@brvaland I think the redirect to okta behavior is caused by the SecureRoute (from okta-react), you can provide an onAuthRequired to customize the behavior.

shuowu avatar Jul 15 '21 16:07 shuowu