Skip to content

Commit

Permalink
Display IDP Display Name instead of IDP Alias
Browse files Browse the repository at this point in the history
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 keycloak#33408

Signed-off-by: Benedikt Rohlf <[email protected]>
  • Loading branch information
NobelNerdBenne authored and ahus1 committed Dec 17, 2024
1 parent efb27f6 commit 1f278b7
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 1f278b7

Please sign in to comment.