8000 Localization: when the user has forgotten the password, the email is sent in default language, instead of the selected one · Issue #36986 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Localization: when the user has forgotten the password, the email is sent in default language, instead of the selected one #36986
Closed
@iliuta

Description

@iliuta

Before reporting an issue

  • I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

Area

login/ui

Describe the bug

Hi,

I have a realm with localization activated and some supported locales, English, French, Italian and Spanish.
The default locale is English.

The user tries to login. The login screen is correctly displayed in the browser's language, French, probably inferred from the accept-language header.
The user does not remember the password and hits forgot password link.
The "forgot password" form, again, is correctly displayed in the browser's language, French.

The users inputs his email and then submits the form. The reset password mail is sent in English, despite the form's language.

Now, if the user specifically use the language selection list to select his preferred language, then the email is correctly sent in the selected language and not in English.

Version

26.1.0

Regression

  • The issue is a regression

Expected behavior

The reset password email should be sent in the language used for displaying the forget password form.

Actual behavior

The reset password email is sent in English, which is the default locale of the realm.

How to Reproduce?

Already written in the bug description paragraph.

Anything else?

I found this piece of code in org.keycloak.locale.DefaultLocaleSelectorProvider:

    public Locale resolveLocale(RealmModel realm, UserModel user, Theme.Type themeType) {
        HttpHeaders requestHeaders = session.getContext().getRequestHeaders();
        AuthenticationSessionModel session = this.session.getContext().getAuthenticationSession();

        if (!realm.isInternationalizationEnabled()) {
            return Locale.ENGLISH;
        }

        Locale userLocale = getUserLocale(realm, session, user, requestHeaders, themeType);
        if (userLocale != null) {
            return userLocale;
        }

        String realmDefaultLocale = realm.getDefaultLocale();
        if (realmDefaultLocale != null) {
            return Locale.forLanguageTag(realmDefaultLocale);
        }

        return Locale.ENGLISH;
    }
   private Locale getUserLocale(RealmModel realm, AuthenticationSessionModel session, UserModel user, HttpHeaders requestHeaders, Theme.Type themeType) {
        Locale locale;

        locale = getUserSelectedLocale(realm, session);
        if (locale != null) {
            return locale;
        }

        locale = getUserProfileSelection(realm, user);
        if (locale != null) {
            return locale;
        }

        if(Theme.Type.EMAIL.equals(themeType)) {
            return null;
        }

        locale = getClientSelectedLocale(realm, session);
        if (locale != null) {
            return locale;
        }

        locale = getLocaleCookieSelection(realm, requestHeaders);
        if (locale != null) {
            return locale;
        }

        locale = getAcceptLanguageHeaderLocale(realm, requestHeaders);
        if (locale != null) {
            return locale;
        }

        return null;
    }

So, the user didn't select any locale, never touched to his user profile and the themeType must be email, therefore getUserLocale returns null and the email is sent in realm's default language.

Next, if the user selects a locale from the dropdown menu, then getUserLocale falls into the first case and returns the selected one, hence the mail sent in the right language.

That would explain the behaviour but it's still not correct, in my opinion.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0