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

Let custom OIDC token propagation filters customize the exchange status #36501

Merged
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 @@ -59,13 +59,13 @@ public AccessTokenRequestReactiveFilter() {

@PostConstruct
public void initExchangeTokenClient() {
if (exchangeToken) {
if (isExchangeToken()) {
OidcClients clients = Arc.container().instance(OidcClients.class).get();
String clientName = getClientName();
exchangeTokenClient = clientName != null ? clients.getClient(clientName) : clients.getClient();
Grant.Type exchangeTokenGrantType = ConfigProvider.getConfig()
.getValue(
"quarkus.oidc-client." + (oidcClientName.isPresent() ? oidcClientName.get() + "." : "")
"quarkus.oidc-client." + (clientName != null ? clientName + "." : "")
+ "grant.type",
Grant.Type.class);
if (exchangeTokenGrantType == Grant.Type.EXCHANGE) {
Expand All @@ -79,6 +79,10 @@ public void initExchangeTokenClient() {
}
}

protected boolean isExchangeToken() {
return exchangeToken;
}

@Override
public void filter(ResteasyReactiveClientRequestContext requestContext) {
if (verifyTokenInstance(requestContext)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.quarkus.oidc.token.propagation;

public class CustomAccessTokenRequestFilter extends AccessTokenRequestFilter {

@Override
protected String getClientName() {
return "exchange";
}

@Override
protected boolean isExchangeToken() {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public AccessTokenRequestFilter() {

@PostConstruct
public void initExchangeTokenClient() {
if (exchangeToken) {
if (isExchangeToken()) {
OidcClients clients = Arc.container().instance(OidcClients.class).get();
String clientName = getClientName();
exchangeTokenClient = clientName != null ? clients.getClient(clientName) : clients.getClient();
Grant.Type exchangeTokenGrantType = ConfigProvider.getConfig()
.getValue(
"quarkus.oidc-client." + (oidcClientName.isPresent() ? oidcClientName.get() + "." : "")
"quarkus.oidc-client." + (clientName != null ? clientName + "." : "")
+ "grant.type",
Grant.Type.class);
if (exchangeTokenGrantType == Grant.Type.EXCHANGE) {
Expand All @@ -72,6 +72,10 @@ public void initExchangeTokenClient() {
}
}

protected boolean isExchangeToken() {
return exchangeToken;
}

@Override
public void filter(ClientRequestContext requestContext) throws IOException {
if (acquireTokenCredentialFromCtx(requestContext)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

import org.eclipse.microprofile.rest.client.annotation.RegisterProvider;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import io.quarkus.oidc.token.propagation.AccessToken;

@RegisterRestClient(configKey = "access-token-propagation")
@AccessToken
@RegisterProvider(CustomAccessTokenRequestFilter.class)
@Path("/")
public interface AccessTokenPropagationService {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.quarkus.it.keycloak;

import io.quarkus.oidc.token.propagation.AccessTokenRequestFilter;

public class CustomAccessTokenRequestFilter extends AccessTokenRequestFilter {
@Override
protected String getClientName() {
return "exchange-token";
}

@Override
protected boolean isExchangeToken() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ quarkus.oidc-client.exchange-token.credentials.secret=${quarkus.oidc.credentials
quarkus.oidc-client.exchange-token.grant.type=exchange
quarkus.oidc-client.exchange-token.grant-options.exchange.audience=quarkus-app-exchange

quarkus.oidc-token-propagation.exchange-token=true
quarkus.oidc-token-propagation.client-name=exchange-token

quarkus.rest-client.jwt-token-propagation.uri=http://localhost:8081/protected
quarkus.rest-client.jwt-token-propagation.verify-host=false
quarkus.rest-client.access-token-propagation.uri=http://localhost:8081/protected
Expand Down
Loading