authts / oidc-client-ts

OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
https://authts.github.io/oidc-client-ts/
Apache License 2.0
1.34k stars 199 forks source link

Getting "No matching state found in storage" error #1487

Open YogiDhingani27 opened 4 months ago

YogiDhingani27 commented 4 months ago

When I'm trying to visit a url which has a code as a query param then authentication is failing and giving this error.

Other urls are working fine for ex: http://localhost:3004/integration

Not working url:

http://localhost:3000/integration?state=%7B%22uuid%22:%20%1234%22,%20%22platform%22:%20%22google%22%7D&code=1233434&scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/drive.readonly%20openid&authuser=0&hd=werwer.com&prompt=consent

image

Note: Excluding url having code as a query parameter other urls are working fine.

I want a code query parameter in my url for OAuth related authentication.

YogiDhingani27 commented 4 months ago

UserManager Configuration:

export const userManager = new UserManager({ authority: authority, client_id: clientId, redirect_uri: window.location.origin + window.location.pathname, post_logout_redirect_uri: window.location.origin, monitorSession: true });

I'm using keycloak for authentication.

pamapa commented 4 months ago

You will need to debug/log your specific application issue. Using https://authts.github.io/oidc-client-ts/#md:logging.

When the authentication process starts this library add a state to the session storage, this state later when the callback is received must be found again.

Store: https://github.com/authts/oidc-client-ts/blob/main/src/OidcClient.ts#L145 Read: https://github.com/authts/oidc-client-ts/blob/main/src/OidcClient.ts#L159

YogiDhingani27 commented 4 months ago

@pamapa I'm using keycloak for authentication there is nothing i can debug. Initiallly when i hit the url, keycloak will automatically append the code into url for authentication purpose. So i think oidc is considering the wrong code for authentication as above mentioned. i have a two code keys.

And above mentioned url is working if i'm using react-keycloak/web.

vvikene commented 1 month ago

Are you doing a round trip every time you visit a page? You are using whatever page visited as the redirect callback url.. how do you check if it's a redirect callback or not?

YogiDhingani27 commented 1 month ago

Are you doing a round trip every time you visit a page? You are using whatever page visited as the redirect callback url.. how do you check if it's a redirect callback or not?

I'm not checking the redirect url. oidc is giving the error when you have code query param in url.

YogiDhingani27 commented 1 month ago

Here is the video of the issue which you can refer:

As you can see in this video. Issue is facing when url includes state and code as a query params, for other cases it is working as expected.

keycloak-issue.webm

YogiDhingani27 commented 1 month ago

Hi @pamapa,

If user includes state and code as a query params in url then it is giving this error.

Can you please help me how can i solve this issue?

Thanks!

Hatko commented 2 weeks ago

Having the same issue