Skip to content
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

Ask for username on reauthentication when no session present #486

Merged
merged 2 commits into from
Dec 17, 2024
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 @@ -32,11 +32,13 @@ void forceChallenge() {

String rememberMeUsername = rememberMe.getUserName();

Response challengeResponse;
if (reauthentication.required() && context.getUser() != null) {
String attribute = Optional.ofNullable(context.getAuthenticatorConfig())
.map(it -> it.getConfig().getOrDefault("userAttribute", "email").trim())
.orElse("email");
formData.add(AuthenticationManager.FORM_USERNAME, context.getUser().getFirstAttribute(attribute));
challengeResponse = loginForm.createWithSignInButtonOnly(formData);
} else {
if (loginHintUsername != null || rememberMeUsername != null) {
if (loginHintUsername != null) {
Expand All @@ -46,12 +48,6 @@ void forceChallenge() {
formData.add("rememberMe", "on");
}
}
}

Response challengeResponse;
if (reauthentication.required()) {
challengeResponse = loginForm.createWithSignInButtonOnly(formData);
} else {
challengeResponse = loginForm.create(formData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,29 @@ public void willForwardLoginHint() {
}
}

@Nested
@DisplayName("GH-475: Given no session and prompt=login")
class GivenNoSessionAndPromptLogin {

@BeforeEach
public void setUp() {
upstreamIdpMock().redirectToDownstreamWithPromptLogin("test");
}

@Test
@DisplayName("then show username form field")
public void thenShowUsernameFormField() {
testRealmLoginPage().assertUsernameFieldIsDisplayed();
}

@Test
@DisplayName("then username form field is empty")
public void thenUsernameFormFieldIsEmpty() {
testRealmLoginPage().assertUsernameFieldIsPrefilledWith("");
}

}

@Nested
@DisplayName("Given user is linked to an IdP already")
class GivenUserHasIdpLinkConfigured {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ public void redirectToDownstreamWithLoginHint(String clientId, String loginHint)
webDriver.navigate().to(keycloakBaseUrl + url);
}

public void redirectToDownstreamWithPromptLogin(String clientId) {
String url = "/realms/test-realm/protocol/openid-connect/auth?client_id=" + clientId + "&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Frealms%2Ftest-realm%2Faccount%2F&response_mode=fragment&response_type=code&scope=openid";
url += "&prompt=login";
webDriver.navigate().to(keycloakBaseUrl + url);
}

}
Loading