Error: No matching state found in storage - at OidcClient.readSigninResponseState
Hi@all
When I refresh the page, I get logged out. Reproduce:
- Click login button
- Login via keycloak/openid
- 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)
- Refresh page (Command+R)
- 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?
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...