From 1f278b75fc550bc6524c526fd72b66661851e2f5 Mon Sep 17 00:00:00 2001 From: Benedikt Rohlf Date: Sat, 12 Oct 2024 10:09:11 +0200 Subject: [PATCH] Display IDP Display Name instead of IDP Alias This commit close the Issue where the IDP alias is displayed instead of the IDP display name in the existing account link. The alias will continue to be used when no display name is set. Close #33408 Signed-off-by: Benedikt Rohlf --- .../authenticators/broker/IdpUsernamePasswordForm.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/src/main/java/org/keycloak/authentication/authenticators/broker/IdpUsernamePasswordForm.java b/services/src/main/java/org/keycloak/authentication/authenticators/broker/IdpUsernamePasswordForm.java index 482824520354..af863c096789 100755 --- a/services/src/main/java/org/keycloak/authentication/authenticators/broker/IdpUsernamePasswordForm.java +++ b/services/src/main/java/org/keycloak/authentication/authenticators/broker/IdpUsernamePasswordForm.java @@ -26,10 +26,12 @@ import org.keycloak.authentication.authenticators.browser.UsernamePasswordForm; import org.keycloak.broker.provider.BrokeredIdentityContext; import org.keycloak.forms.login.LoginFormsProvider; +import org.keycloak.models.IdentityProviderModel; import org.keycloak.models.UserModel; import org.keycloak.models.utils.FormMessage; import org.keycloak.services.managers.AuthenticationManager; import org.keycloak.services.messages.Messages; +import org.keycloak.services.validation.Validation; import java.util.Optional; @@ -88,12 +90,14 @@ protected LoginFormsProvider setupForm(AuthenticationFlowContext context, Multiv throw new AuthenticationFlowException("Not found serialized context in clientSession", AuthenticationFlowError.IDENTITY_PROVIDER_ERROR); } + IdentityProviderModel idpModel = context.getSession().identityProviders().getByAlias(serializedCtx.getIdentityProviderId()); + existingUser.ifPresent(u -> formData.putSingle(AuthenticationManager.FORM_USERNAME, u.getUsername())); LoginFormsProvider form = context.form() .setFormData(formData) .setAttribute(LoginFormsProvider.REGISTRATION_DISABLED, true) - .setInfo(Messages.FEDERATED_IDENTITY_CONFIRM_REAUTHENTICATE_MESSAGE, serializedCtx.getIdentityProviderId()); + .setInfo(Messages.FEDERATED_IDENTITY_CONFIRM_REAUTHENTICATE_MESSAGE, Validation.isBlank(idpModel.getDisplayName()) ? idpModel.getAlias() : idpModel.getDisplayName()); SerializedBrokeredIdentityContext serializedCtx0 = SerializedBrokeredIdentityContext.readFromAuthenticationSession(context.getAuthenticationSession(), AbstractIdpAuthenticator.NESTED_FIRST_BROKER_CONTEXT); if (serializedCtx0 != null) {