-
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.
- Loading branch information
1 parent
77cf0a8
commit bd52f6f
Showing
11 changed files
with
284 additions
and
28 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
21 changes: 21 additions & 0 deletions
21
extensions/oidc/runtime/src/main/java/io/quarkus/oidc/OidcRedirectFilter.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,21 @@ | ||
package io.quarkus.oidc; | ||
|
||
import io.vertx.ext.web.RoutingContext; | ||
|
||
/** | ||
* OIDC redirect filter which can be used to customize redirect requests to OIDC authorization and logout endpoints | ||
* as well as local redirects to OIDC tenant error, session expired and other pages. | ||
*/ | ||
public interface OidcRedirectFilter { | ||
/** | ||
* Filter OIDC redirect. | ||
* | ||
* @param routingContext the routing context that can be used to set additional cookies. | ||
* @param oidcConfig current OIDC tenant configuration. | ||
* @param redirectUri the redirect uri which filters may update by adding additional query parameters. | ||
* @param tokenClaims the decoded JWT token claims in JSON format. If necessary, implementations can convert it to JSON | ||
* object. | ||
* @return redirectUri the redirect uri which can have additional query parameters added. | ||
*/ | ||
String filter(RoutingContext routingContext, OidcTenantConfig oidcConfig, String redirectUri); | ||
} |
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
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
38 changes: 38 additions & 0 deletions
38
...n-tests/oidc-code-flow/src/main/java/io/quarkus/it/keycloak/CustomOidcRedirectFilter.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,38 @@ | ||
package io.quarkus.it.keycloak; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import org.eclipse.microprofile.jwt.Claims; | ||
|
||
import io.quarkus.arc.Unremovable; | ||
import io.quarkus.oidc.AuthorizationCodeTokens; | ||
import io.quarkus.oidc.OidcRedirectFilter; | ||
import io.quarkus.oidc.OidcTenantConfig; | ||
import io.quarkus.oidc.TenantFeature; | ||
import io.quarkus.oidc.runtime.OidcUtils; | ||
import io.smallrye.jwt.build.Jwt; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
@ApplicationScoped | ||
@Unremovable | ||
@TenantFeature("tenant-refresh") | ||
public class CustomOidcRedirectFilter implements OidcRedirectFilter { | ||
|
||
@Override | ||
public String filter(RoutingContext routingContext, OidcTenantConfig oidcConfig, String redirectUri) { | ||
if (!"tenant-refresh".equals(oidcConfig.tenantId.get())) { | ||
throw new RuntimeException("Invalid tenant id"); | ||
} | ||
if (redirectUri.endsWith("/session-expired-page")) { | ||
|
||
AuthorizationCodeTokens tokens = routingContext.get(AuthorizationCodeTokens.class.getName()); | ||
String userName = OidcUtils.decodeJwtContent(tokens.getIdToken()).getString(Claims.preferred_username.name()); | ||
String jwe = Jwt.preferredUserName(userName).jwe().encryptWithSecret(oidcConfig.credentials.secret.get()); | ||
OidcUtils.createCookie(routingContext, oidcConfig, "session_expired", | ||
jwe + "|" + oidcConfig.tenantId.get(), 10); | ||
return redirectUri + "?session-expired=true"; | ||
} | ||
return redirectUri; | ||
} | ||
|
||
} |
Oops, something went wrong.