mauriciovigolo / keycloak-angular

Easy Keycloak setup for Angular applications.
MIT License
730 stars 280 forks source link

Login method locale is not changing the user locale when the user logs in #542

Open maripop opened 9 months ago

maripop commented 9 months ago

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search for issues before submitting
- [ ] feature request

Versions.

angular: 16.2.0 keycloak-angular: 14.1.0 keycloak-js: 22.0.4 keycloak: 19.0.1

Repro steps.

Using an instance of KeycloakService we have implemented the login. First calling init with configuration, client and realm data. If not logged, we call the KeycloakService instance login method with action login and the chosen locale.

import { Injectable } from "@angular/core";
import { KeycloakService } from "keycloak-angular";

@Injectable()
export class KeycloakAdapter {
  keycloakInstance: KeycloakService;

  constructor() {
    this.keycloakInstance = new KeycloakService();
  }

  login(locale: string): void {
    this.keycloakInstance
      .init({
        config: {
          realm: "real_name",
          clientId: "client_id",
          url: "KEYCLOAK_URL",
        },
        initOptions: {
          onLoad: "check-sso",
          enableLogging: true,
          messageReceiveTimeout: 5000,
        },
      })
      .then((loggedIn: boolean) => {
        if (!loggedIn) {
          this.keycloakInstance.login({ action: "login", locale });
        } else {
          // logged actions
        }
      });
  }
}

This is redirecting to keycloak login with ui_locale parameter setted with the locale passed. The keycloak login is shown translated with this locale and the language selector has this locale selected. In keycloak, the realm authentication configuration has the "update user locale" required action enable.

imagen

The issue is that, when the user logs in, the user locale is not changed, so remains the previous one. The user locale only is already changed when the locale is changed in keycloak login page, but not with the locale passed with KeycloakService login method. When the user changes the locale in keycloak login page, the url parametter setted with the chosen one is kc_locale instead of ui_locale.

imagen

Desired functionality.

The expected behavior is that, the locale passed to KeycloakService login method and setted in keyclok url ui_locale parametter, changes the user locale when the user logs in.