IdentityModel / oidc-client-js

OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
Apache License 2.0
2.43k stars 840 forks source link

User signed out when calling silent renew #1191

Closed nomttr closed 3 years ago

nomttr commented 4 years ago

Hey,

I was trying to learn a bit about OIDC and React with Redux. I've set up Keycloak, downloaded redux-oidc-example, updated userManagerConfig and configured it to work with Authorization Code Flow.

I run the application, successfully log in by using my IP(Azure AD), it navigates me back to the app, the app is able to get my profile from the access token, but then...after literally few seconds it signs me out. I hit again Login button and the same thing happens.

So I started to dig into this and it seems that the issues is with automatic silent renew - anytime the code goes through the defined silent_redirect_uri page user is automatically signed out. I've checked Keycloak configuration and userManagerConfig but I do not see any mistakes there. What's even more interesting - this issue occurs only on Chrome(I'm using v. 85.0.4183.83) - on Edge/Firefox/Chrome Dev everything works properly.

I have seen that a lot of people have had the same issue and the solution for that was to disable automaticSilentRenew in userManagerConfig but that's not solution for me as I want to have this enabled.

Any ideas why is this happening?

const userManagerConfig = {
  authority:
    "https://blablabla/auth/realms/master/",
  client_id: "PGPlatform.Gateway",
  redirect_uri: `${window.location.protocol}//${window.location.hostname}${
    window.location.port ? `:${window.location.port}` : ""
  }/callback`,
  response_type: "code",
  scope: "openid profile api",
  silent_redirect_uri: `${window.location.protocol}//${
    window.location.hostname
  }${window.location.port ? `:${window.location.port}` : ""}/silent_renew.html`,
  automaticSilentRenew: true,  
  filterProtocolClaims: true,
  loadUserInfo: true,
};

Keycloak Token config image

Redux actions image

Network image

brockallen commented 4 years ago

Sounds like the recent cross-site cookie changes in chrome. In short, cookies cross-site in an iframe won't work anymore. I'd suggest stop doing JS apps that do cross-site OIDC and instead use a BFF pattern instead.

MaxTibs commented 4 years ago

I've had this issue as well. My Keycloak version was 8.0.1 and it doesn't support the Google Chrome Update concerning the SameSite cookie. If you update your Keycloak to a version greater or equal to 8.0.2 it should resolves the problem. See the Keycloak changelog by yourself: https://www.keycloak.org/docs/latest/release_notes/#keycloak-8-0-2

Hope it helps :)

nomttr commented 4 years ago

I've had this issue as well. My Keycloak version was 8.0.1 and it doesn't support the Google Chrome Update concerning the SameSite cookie. If you update your Keycloak to a version greater or equal to 8.0.2 it should resolves the problem. See the Keycloak changelog by yourself: https://www.keycloak.org/docs/latest/release_notes/#keycloak-8-0-2

Hope it helps :)

Thanks - I'll definitely give a try to it 👍

brockallen commented 3 years ago

I think you're all set on this now so closing.