mattmorg55 / Owin.Security.Keycloak

Keycloak Authentication Middleware for the C# OWIN Pipeline
http://keycloak.jboss.org
MIT License
17 stars 20 forks source link

add option for ui_localales query param for proper login page localization #21

Open molequetu opened 3 years ago

molequetu commented 3 years ago

Hello, we had the request to retrieve the login page based on the current ui culture set on the application using the adapter, so we add the option in order to set the desired locale for retrieving the login page. By default keycloack wil render the login page localized based on these conditions:

With internationalization enabled, the locale is resolved in the following priority:

  1. kc_locale query parameter
  2. KEYCLOAK_LOCALE cookie value
  3. User’s preferred locale if a user instance is available
  4. ui_locales query parameter
  5. Accept-Language request header
  6. Realm’s default language

So, our issue was, suppose our application was starting with a defined uiCulture, the login page was rendered base on 5(Accept-Language) header, which many times was different from the defined in the application.

All you need, which is optional, is to configure your adapter with this parameter, e.g

app.UseKeycloakAuthentication(new KeycloakAuthenticationOptions {
....other initialiation config options
 UiLocales = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName
}

Be carefull to have your desired ui culture(based on web.config or whatever) before keycloak initialization.