AxaFrance / oidc-client

Light, Secure, Pure Javascript OIDC (Open ID Connect) Client. We provide also a REACT wrapper (compatible NextJS, etc.).
MIT License
597 stars 160 forks source link

undefined is not valid JSON #871

Closed beanovar closed 1 year ago

beanovar commented 2 years ago

Hi - I'm sorry at this point I'm not sure what it takes to reproduce, will post if I find out. However sometimes the page errors out with the following logs in the console:

SyntaxError: "undefined" is not valid JSON
   at JSON.parse (<anonymous>)
   at getLoginParams (oidc.ts:199:1)
   at Oidc._callee23$ (oidc.ts:963:1)
   ....
   at localsilentLoginAsync (oidc.ts:961:1)
refreshTokensAsync_silent_error {"message":"exceptionSilent","exception":"\"undefined\" is not valid JSON"}

Do you know what would cause this at all?

Thankyou

guillaume-chervet commented 2 years ago

Hi @beanovar thank you very much for your issue.

Do you have a sample of your configuration? Does it occur quickly or after a big amount of time? Does it occur often?

beanovar commented 2 years ago

Hi - I might see it every 3 or so days? Only after a big amount of time, maybe while the page is in the background. Haven't seen the pattern yet, or how to reproduce.

Our config sets

I will let you know if I see what can re-produce it. Thanks

guillaume-chervet commented 2 years ago

Thank you @beanovar, on which browser do you have this error?

beanovar commented 2 years ago

Chrome - I'm going to close this for now as I have not seen it for a while and think it was to something to do with the authentication server returning bad responses. It might be helpful to review what the lib might do if the auth server returns unexpected results or errors? It could be something else entirely though, just guessing. Thanks!

guillaume-chervet commented 2 years ago

Thank you @beanovar , i think it migth have something link with session livecycle. If you have the problem back you can reopen the issue.

beanovar commented 2 years ago

I found out how to reproduce this ! 1) Have two tabs open, one in the foreground, one in the background (hidden) 2) Ensure the auth server is down / returns an error response when the visible tab refreshes it's token. 3) Let it retry the 4 times before eventually failing. 4) Now make the second tab visible, and you will see the "undefined" is not valid JSON in that tab's console.

Ideally, I would like all tabs to recover automatically once the auth sever has recovered... maybe they could continue trying rather than give up after 4 attempts?

Thanks!

guillaume-chervet commented 2 years ago

Thank you very much for this !

I will fix it as soon as possible. Yes may be retry whithout limit in certain situation may work for this issue.

alex-airbox commented 1 year ago

Edit: Tried on 6.6.7, works fine. Fails on 6.13.1

I may have a similar issue on 6.13.1. The config is set with:

My app at the moment simply renders a paragraph inside a OidcSecure, and on load it will go to Keycloak, I log in and then on redirect it will render the failed screen. Console simply shows:

index.js:1 SyntaxError: "undefined" is not valid JSON
    at JSON.parse (<anonymous>)
    at Object.getLoginParams (initSession.ts:61:1)
    at _callee3$ (login.ts:131:1)
    at tryCatch (regeneratorRuntime.js:86:1)
    at Generator._invoke (regeneratorRuntime.js:66:1)
    at Generator.next (regeneratorRuntime.js:117:1)
    at fulfilled (initWorker.ts:143:1)

Tried on Chrome and Firefox, same result.

guillaume-chervet commented 1 year ago

Thank you @alex-airbox for the feedback. Very sorry I just fix it. Version 6.13.2 work with localStorage.

alex-airbox commented 1 year ago

Apologies for not sending feedback last week, I went back to an old version as I had issues with the log out. After a auth.logout('/'); it'd successfully log me out but I won't be able to log in again, I think issue was undefined tokens this time. Solved going back to 6.6.7.

Zhuohui-Li commented 1 year ago

Hi @guillaume-chervet in version 6.13.3 I got

oidc.ts:223 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'refreshToken')
    at _callee5$ (oidc.ts:223:1)
    at tryCatch (regeneratorRuntime.js:86:1)
    at Generator._invoke (regeneratorRuntime.js:66:1)
    at Generator.next (regeneratorRuntime.js:117:1)
    at fulfilled (noHashQueryStringUtils.ts:11:1)
guillaume-chervet commented 1 year ago

Thank you @alex-airbox for the feedback :)

guillaume-chervet commented 1 year ago

@Zhuohui-Li what does look like your configuration ? I cannot reproduce it.

guillaume-chervet commented 1 year ago

Hi close this issue. I think it is resolved. Feel free to reopen it if you need.