Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keycloak / Angular - Always "invalid redirect_uri"

I have now looked through various questions & answers here, but cannot find a solution. The login and its redirect work perfectly. Only when I log in, I always get "invalid redirect_uri". The URL returns exactly the address of the service:

Service-URL: https://subdomain.subdomain.xy-lab.ch Redirect-URI in URL: https://subdomain.subdomain.xy-lab.ch/ (https://lernoase-auth.subdomain.xy-lab.ch/realms/Lernnomaden/protocol/openid-connect/logout?redirect_uri=https%3A%2F%2Fsubdomain.subdomain.xy-lab.ch)

I have tested all possible combinations of the URL in Keycloak. With and without HTTPS, "" "/" & "/*", etc. What could be the reason?

My Keycloak-Config for ln-frontend looks like this:

enter image description here

Angular I used keycloak-angular and is configured as follows:

// enviroment.json
const keycloakConfig: KeycloakConfig = {
  url: 'https://lernoase-auth.subdomain.xy-lab.ch/',
  realm: 'Lernnomaden',
  clientId: 'ln-frontend',
};

// keycloak-initializer.js
export function initializer(keycloak: KeycloakService): () => Promise<boolean> {
  const options: KeycloakOptions = {
    config: environment.keycloak,
    loadUserProfileAtStartUp: true,
    initOptions: {
      onLoad: 'check-sso',
      silentCheckSsoRedirectUri: window.location.origin + '/assets/silent-check-sso.html',
    },
  };

  return () => keycloak.init(options);
}
like image 620
Sven M. Avatar asked Dec 11 '25 21:12

Sven M.


1 Answers

I am facing the same issue with the following versions:

  • Angular: 14.x
  • keycloak-angular: 12.x
  • keycloak-js: 19.x
  • keycloak: 19.x

As far as I understand keycloak introduced a new URL post_logout_redirect_uri param to follow Open ID connect guidelines. Make sure to also set parameter "Valid post logout redirect URIs" in your client access settings in the keycloak admin console.

Attached you will find a screenshot of admin console

like image 193
Jenö Kolbe Avatar answered Dec 13 '25 14:12

Jenö Kolbe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!