Skip to content

Commit

Permalink
Let custom OIDC token propagation filters provide client name
Browse files Browse the repository at this point in the history
  • Loading branch information
sberyozkin committed Oct 12, 2023
1 parent 2700890 commit 283389b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public AccessTokenRequestReactiveFilter() {
public void initExchangeTokenClient() {
if (exchangeToken) {
OidcClients clients = Arc.container().instance(OidcClients.class).get();
exchangeTokenClient = oidcClientName.isPresent() ? clients.getClient(oidcClientName.get()) : clients.getClient();
String clientName = getClientName();
exchangeTokenClient = clientName != null ? clients.getClient(clientName) : clients.getClient();
Grant.Type exchangeTokenGrantType = ConfigProvider.getConfig()
.getValue(
"quarkus.oidc-client." + (oidcClientName.isPresent() ? oidcClientName.get() + "." : "")
Expand Down Expand Up @@ -113,6 +114,10 @@ public void accept(Throwable t) {
}
}

protected String getClientName() {
return oidcClientName.orElse(null);
}

public void propagateToken(ResteasyReactiveClientRequestContext requestContext, String accessToken) {
if (accessToken != null) {
requestContext.getHeaders().add(HttpHeaders.AUTHORIZATION, BEARER_SCHEME_WITH_SPACE + accessToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public AccessTokenRequestFilter() {
public void initExchangeTokenClient() {
if (exchangeToken) {
OidcClients clients = Arc.container().instance(OidcClients.class).get();
exchangeTokenClient = oidcClientName.isPresent() ? clients.getClient(oidcClientName.get()) : clients.getClient();
String clientName = getClientName();
exchangeTokenClient = clientName != null ? clients.getClient(clientName) : clients.getClient();
Grant.Type exchangeTokenGrantType = ConfigProvider.getConfig()
.getValue(
"quarkus.oidc-client." + (oidcClientName.isPresent() ? oidcClientName.get() + "." : "")
Expand Down Expand Up @@ -92,6 +93,10 @@ private String exchangeTokenIfNeeded(String token) {
}
}

protected String getClientName() {
return oidcClientName.orElse(null);
}

private boolean acquireTokenCredentialFromCtx(ClientRequestContext requestContext) {
if (enabledDuringAuthentication) {
TokenCredential tokenCredential = getTokenCredentialFromContext();
Expand Down

0 comments on commit 283389b

Please sign in to comment.