Franpastoragusti / oidc-react-app

Oidc Client implementation with React Context and react-router-dom, to manage the auth process and manage private and public routes
43 stars 23 forks source link

Error: "No state in response" #1

Closed francoguilherme closed 4 years ago

francoguilherme commented 5 years ago

Hi, I implemented your code in my app but I'm having some problems.

When I try to login, in the path "/signin-oidc" I get: *Info* "UserManager._loadUser: no user storageString" *Info* "UserManager.getUser: user not found in storage" *Error* "OidcClient.processSigninResponse: No state in response".

When I change the function in callback.js from signinRedirectCallback to signinRedirect, the app successfully redirects me to the Signin page, but after signing in the tokens are not set in the local storage, so when the PrivateRoute runs isAuthenticated() it's always false and falls in an infinite loop of signinRedirect().

Can you help me figure out what I'm doing wrong? I suppose i can't change the function callback.js, but I couldn't fix the "No state in response error".

svict4 commented 5 years ago

Did you end up finding a fix for this?

svict4 commented 5 years ago

okay you simply need to have a conditional to check if the server has already responded and run signinRedirectCallback or signinRedirect depending on the state

export const Callback = () => (
  <AuthConsumer>
    {({ signinRedirect, signinRedirectCallback }) => {
      if (Boolean(window.location.hash)) { // depends on IDENTITY_CONFIG.response_type
        signinRedirectCallback();
      } else {
        signinRedirect();
      }
    }}
  </AuthConsumer>
);