-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23274 from sberyozkin/oidc_web_app_code_param
Process OIDC code query param only if the state cookie exists
- Loading branch information
Showing
8 changed files
with
161 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...tests/oidc-code-flow/src/main/java/io/quarkus/it/keycloak/CustomTenantConfigResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import io.quarkus.oidc.OidcRequestContext; | ||
import io.quarkus.oidc.OidcTenantConfig; | ||
import io.quarkus.oidc.OidcTenantConfig.ApplicationType; | ||
import io.quarkus.oidc.TenantConfigResolver; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
@ApplicationScoped | ||
public class CustomTenantConfigResolver implements TenantConfigResolver { | ||
|
||
@Inject | ||
@ConfigProperty(name = "quarkus.oidc.auth-server-url") | ||
String authServerUrl; | ||
|
||
OidcTenantConfig config = new OidcTenantConfig(); | ||
|
||
public CustomTenantConfigResolver() { | ||
} | ||
|
||
@PostConstruct | ||
public void initConfig() { | ||
config.setTenantId("tenant-before-wrong-redirect"); | ||
config.setAuthServerUrl(authServerUrl); | ||
config.setClientId("quarkus-app"); | ||
config.getCredentials().setSecret("secret"); | ||
config.setApplicationType(ApplicationType.WEB_APP); | ||
} | ||
|
||
@Override | ||
public Uni<OidcTenantConfig> resolve(RoutingContext context, OidcRequestContext<OidcTenantConfig> requestContext) { | ||
if (context.request().path().contains("callback-before-wrong-redirect")) { | ||
if (context.getCookie("q_auth_tenant-before-wrong-redirect") != null) { | ||
// trigger the code to access token exchange failure due to a redirect uri mismatch | ||
config.authentication.setRedirectPath("wrong-path"); | ||
} | ||
return Uni.createFrom().item(config); | ||
} | ||
return Uni.createFrom().nullItem(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...gration-tests/oidc-code-flow/src/main/java/io/quarkus/it/keycloak/ProtectedResource3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.InternalServerErrorException; | ||
import javax.ws.rs.Path; | ||
|
||
import io.quarkus.security.Authenticated; | ||
|
||
@Path("/web-app3") | ||
@Authenticated | ||
public class ProtectedResource3 { | ||
|
||
@GET | ||
public String getName() { | ||
// CodeFlowTest#testAuthenticationCompletionFailedNoStateCookie checks that if a state cookie is missing | ||
// then 401 is returned when a redirect targets the endpoint requiring authentication | ||
throw new InternalServerErrorException("This method must not be invoked"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.