8000 feat: organization authenticator : bypass username form when login_hint is set by olivierboudet · Pull Request #39432 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: organization authenticator : bypass username form when login_hint is set #39432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.keycloak.organization.utils.Organizations.getEmailDomain;
import static org.keycloak.organization.utils.Organizations.isEnabledAndOrganizationsPresent;
import static org.keycloak.organization.utils.Organizations.resolveHomeBroker;
import static org.keycloak.utils.StringUtil.isNotBlank;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -64,6 +65,8 @@

public class OrganizationAuthenticator extends IdentityProviderAuthenticator {

private static final String LOGIN_HINT_ALREADY_HANDLED = "loginHintAlreadyHandled";

private final KeycloakSession session;

public OrganizationAuthenticator(KeycloakSession session) {
Expand All @@ -79,6 +82,16 @@ public void authenticate(AuthenticationFlowContext context) {
return;
}

String loginHint = session.getContext().getAuthenticationSession().getClientNote(OIDCLoginProtocol.LOGIN_HINT_PARAM);

if (isNotBlank(loginHint) && !"true".equals(context.getAuthenticationSession().getClientNote(LOGIN_HINT_ALREADY_HANDLED))) {
UserModel user = resolveUser(context, loginHint);
context.setUser(user);

// set auth note to true to handle login_hint only once, we don't want to handle it again after a flow restart
context.getAuthenticationSession().setClientNote(LOGIN_HINT_ALREADY_HANDLED, "true");
}

OrganizationModel organization = Organizations.resolveOrganization(session);

if (organization == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,9 @@ public void testLoginHint() {
String expectedUsername = URLEncoder.encode(member.getEmail(), StandardCharsets.UTF_8);
oauth.realm(bc.consumerRealmName());
oauth.loginForm().loginHint(expectedUsername).open();
assertThat(loginPage.getUsername(), Matchers.equalTo(URLDecoder.decode(expectedUsername, StandardCharsets.UTF_8)));
assertThat(loginPage.getAttemptedUsername(), Matchers.equalTo(URLDecoder.decode(expectedUsername, StandardCharsets.UTF_8)));

// continue authenticating without setting the username
loginPage.clickSignIn();
loginPage.login(memberPassword);
appPage.assertCurrent();
}
Expand Down
Loading
0