Bug: Bad authorization state. Refreshing the page might solve the issue. ( #89
Replies: 12 comments 17 replies
-
Could you be running into this issue? https://github.com/soofstad/react-oauth2-pkce#after-redirect-back-from-auth-provider-with-code-no-token-request-is-made Specifically:
|
Beta Was this translation helpful? Give feedback.
-
Yeah I read about it and it's not this case. When I'm redirected from my provider everything works fine. It happens when I enter the page -> provider/ library somehow remembers session -> no redirect to provider to login -> error 'bad authorization state...' All my routes are wrapper inside AuthProvider. AuthProvider is in index.sx and App routes in App.tsx one level lower |
Beta Was this translation helpful? Give feedback.
-
Are you able to make minimal example on how to recreate this bug? If not, I'd like so see the state of localStorage, both before and after you are redirected to the authentication provider. If everything there looks alright, then you should have a look at what parameters the auth servers sets when it redirects you back after login. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Have you tried clearing all the web apps persistent data? Calling "logout()" should be enough. If you wan't some more help with this, I realy need an example on how to recreate it. |
Beta Was this translation helpful? Give feedback.
-
@pablojakub Do you use Next.js? I am experiencing this same issue right now after migrating over to the new App router. |
Beta Was this translation helpful? Give feedback.
-
Hello @soofstad , I'm also encountering this issue |
Beta Was this translation helpful? Give feedback.
-
Another concern of mine is that when we have this Bad Authorization State, Logout does nothing. It does not try to redirect to keycloak to log in again. So in the case where we send the token in api calls, the api would respond with an 401 Unauthorized error, we would not be able to run logout to redirect to the login page and the user would be left stranded in a gui with no data. |
Beta Was this translation helpful? Give feedback.
-
I have another situation where Bad Authorisation State may occur (and I don't think there is much you can do about it to be honest). When you specify a keycloak url that doesn't point to keycloak but somehow returns a 200 response you get the 'Bad Authorization State' error, the gui is loaded anyway and logout does nothing. (Or appears to do nothing) |
Beta Was this translation helpful? Give feedback.
-
@soofstad Is there any ETA on this issue please? Sorry for asking but my manager is pressuring me. |
Beta Was this translation helpful? Give feedback.
-
From what I can gather, there is no bug, and everything is working as intended. If the user aborts the login process at the auth provider and goes back to the app, we have no other choice than to raise this error. The error in question is a bit vague; 'Bad authorization state. Refreshing the page might solve the issue.' |
Beta Was this translation helpful? Give feedback.
-
This might be unrelated to the problems described here, but we have a page where we encountered the "Bad Authorization State" often in development. It turned out that we used multiple windows with our site in the same browser and when the token needed to be refreshed, multiple instances of the page tried to update the auth tokens at the same time. This resulted in a race condition where the active page sometimes failed with "Bad Authorization State" The solution for us was to change the storage from "local" to "session" as it will not be shared between tabs. This might not be a solution that is generally applicable, but could grant some insight to users ending up here in the future |
Beta Was this translation helpful? Give feedback.
-
Hello,
In my react React I've got an error when I first time enter the page:
THis may indicates that in my url there is no 'code' query. Indeed there is no 'code' query and after reloading the page it is.
I tried to change settings in my router:
Right now default page redirects to /dashboard. But even when I delete it doesn't work.
In TAuthConfig I have autoLogin: true and clearURL: false,
I'am using this verson:
My expected behaviour - login wihout refreshing the page. Of course I can force login() method but it does not do the trick for me in this case
Beta Was this translation helpful? Give feedback.
All reactions