okta / okta-auth-js

The official js wrapper around Okta's auth API
Other
453 stars 265 forks source link

Okta Auth in PWA with offline access #688

Open brvaland opened 3 years ago

brvaland commented 3 years ago

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

aarongranick-okta commented 3 years ago

@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.

brvaland commented 3 years ago

@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 commented 3 years ago

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

shuowu commented 3 years ago

@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.