react-oidc-context icon indicating copy to clipboard operation
react-oidc-context copied to clipboard

Error: No matching state found in storage - at OidcClient.readSigninResponseState

Open approached opened this issue 3 years ago • 1 comments

Hi@all

When I refresh the page, I get logged out. Reproduce:

  1. Click login button
  2. Login via keycloak/openid
  3. Redirect back (address is: https://helpme.test/de/admin/organizations?state=311b124c928e4cd3a5b282fd16dd4475&session_state=2793988e-f78f-4d42-8164-61ab7697af9e&code=4bdf7c6d-7d29-4d8c-95a9-0913b62591a7.2793988e-f78f-4d42-8164-61ab7697af9e.e1f6f519-030c-4204-beab-f4dfe064baa7)
  4. Refresh page (Command+R)
  5. Now i am logout and have follow error

Error:

Error: No matching state found in storage
    at OidcClient.readSigninResponseState (oidc-client-ts.js:1443:1)
    at async UserManager.signinCallback (oidc-client-ts.js:2312:21)
    at async react-oidc-context.js:154:1

oidc-client-ts.js:1443:1:

  async readSigninResponseState(url, removeState = false) {
    const logger2 = this._logger.create("readSigninResponseState");
    const response = new SigninResponse(UrlUtils.readParams(url, this.settings.response_mode));
    if (!response.state) {
      logger2.throw(new Error("No state in response"));
      throw null;
    }
    const storedStateString = await this.settings.stateStore[removeState ? "remove" : "get"](response.state);
    if (!storedStateString) {
=>>>>>>>>>>>>>>>>>>>>>>>      logger2.throw(new Error("No matching state found in storage"));
      throw null;
    }
    const state = SigninState.fromStorageString(storedStateString);

Does anyone have any idea what went wrong?

approached avatar Jul 07 '22 12:07 approached

The Authorization Code Grant with PKCE needs a temporary local state to function.

When creating the sign-in request the oidc-client-ts is storing that state here https://github.com/authts/oidc-client-ts/blob/809da48c91b44df27454d8c0a6a5c04f4e748339/src/OidcClient.ts#L135

When the callback is coming back it needs to match the incoming request against the original request, thus searching for the previous stored state...

In your case somehow this does not work. Best way is to add logging in oidc-client-ts. The state is stored by default in localSession...

pamapa avatar Jul 11 '22 07:07 pamapa