Skip to content

Commit ebf34af

Browse files
committed
Correctly restore query params when OIDC does not drop redirect params
1 parent a34d022 commit ebf34af

File tree

5 files changed

+48
-1
lines changed

5 files changed

+48
-1
lines changed

extensions/oidc/runtime/src/main/java/io/quarkus/oidc/runtime/CodeAuthenticationMechanism.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ public SecurityIdentity apply(SecurityIdentity identity) {
909909
configContext.oidcConfig()));
910910
}
911911
if (finalUserQuery != null) {
912-
finalUriWithoutQuery.append(!removeRedirectParams ? "" : "?");
912+
finalUriWithoutQuery.append(!removeRedirectParams ? "&" : "?");
913913
finalUriWithoutQuery.append(finalUserQuery);
914914
}
915915
String finalRedirectUri = finalUriWithoutQuery.toString();

integration-tests/oidc-code-flow/src/main/java/io/quarkus/it/keycloak/CustomTenantResolver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public String resolve(RoutingContext context) {
2828
return "tenant-query";
2929
}
3030

31+
if (path.contains("tenant-restore-query-keep-redirect-params")) {
32+
return "tenant-restore-query-keep-redirect-params";
33+
}
34+
3135
if (path.contains("tenant-listener")) {
3236
return "tenant-listener";
3337
}

integration-tests/oidc-code-flow/src/main/java/io/quarkus/it/keycloak/ProtectedResource.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@ public String getRefreshTokenTenantListenerCallback() {
309309
return getRefreshToken();
310310
}
311311

312+
@GET
313+
@Path("refresh/tenant-restore-query-keep-redirect-params")
314+
public String getTenantRestoreQueryKeepRedirectParams(@QueryParam("context") String context) {
315+
return getRefreshToken() + ";context=" + context;
316+
}
317+
318+
@GET
319+
@Path("refresh/tenant-restore-query-keep-redirect-params/callback")
320+
public String getTenantRestoreQueryKeepRedirectParamsCallback() {
321+
throw new InternalServerErrorException("This method must not be invoked");
322+
}
323+
312324
@GET
313325
@Path("refresh-query")
314326
public String getRefreshTokenQuery(@QueryParam("a") String aValue) {

integration-tests/oidc-code-flow/src/main/resources/application.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ quarkus.oidc.tenant-listener.authentication.remove-redirect-parameters=false
3636
quarkus.oidc.tenant-listener.authentication.redirect-path=/web-app/refresh/tenant-listener/callback
3737
quarkus.oidc.tenant-listener.application-type=web-app
3838

39+
# Tenant listener configuration for testing that the login event has been captured
40+
quarkus.oidc.tenant-restore-query-keep-redirect-params.auth-server-url=${quarkus.oidc.auth-server-url}
41+
quarkus.oidc.tenant-restore-query-keep-redirect-params.client-id=quarkus-app
42+
quarkus.oidc.tenant-restore-query-keep-redirect-params.credentials.secret=secret
43+
quarkus.oidc.tenant-restore-query-keep-redirect-params.authentication.remove-redirect-parameters=false
44+
quarkus.oidc.tenant-restore-query-keep-redirect-params.authentication.restore-path-after-redirect=true
45+
quarkus.oidc.tenant-restore-query-keep-redirect-params.authentication.redirect-path=/web-app/refresh/tenant-restore-query-keep-redirect-params/callback
46+
quarkus.oidc.tenant-restore-query-keep-redirect-params.application-type=web-app
47+
3948
# Tenant which does not need to restore a request path after redirect, client_secret_post method
4049
quarkus.oidc.tenant-1.auth-server-url=${quarkus.oidc.auth-server-url}
4150
quarkus.oidc.tenant-1.client-id=quarkus-app

integration-tests/oidc-code-flow/src/test/java/io/quarkus/it/keycloak/CodeFlowTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,28 @@ public void testAccessAndRefreshTokenInjectionWithoutIndexHtmlAndListener() thro
15501550
}
15511551
}
15521552

1553+
@Test
1554+
public void testRestoreQueryKeepRedirectParams() throws IOException, InterruptedException {
1555+
try (final WebClient webClient = createWebClient()) {
1556+
HtmlPage page = webClient
1557+
.getPage(
1558+
"http://localhost:8081/web-app/refresh/tenant-restore-query-keep-redirect-params?context=contextValue");
1559+
1560+
assertEquals("Sign in to quarkus", page.getTitleText());
1561+
1562+
HtmlForm loginForm = page.getForms().get(0);
1563+
1564+
loginForm.getInputByName("username").setValueAttribute("alice");
1565+
loginForm.getInputByName("password").setValueAttribute("alice");
1566+
1567+
page = loginForm.getButtonByName("login").click();
1568+
1569+
assertEquals("RT injected;context=contextValue",
1570+
page.getBody().asNormalizedText());
1571+
webClient.getCookieManager().clearCookies();
1572+
}
1573+
}
1574+
15531575
private void doTestAccessAndRefreshTokenInjectionWithoutIndexHtmlAndListener(WebClient webClient)
15541576
throws IOException, InterruptedException {
15551577
HtmlPage page = webClient.getPage("http://localhost:8081/web-app/refresh/tenant-listener");

0 commit comments

Comments
 (0)