-
Hi I'm trying to perform a token exchange using Keycloak in my Quarkus application. I have a realm, and inside it I have a Client and an Identity Provider (Google). What I'm trying to do is, given the access_token coming from Keycloak, perform token exchange to obtain a valid token for Google APIs. I was able to do this normally using curl. As described in the documentation, I created a RestClient: @RegisterRestClient(configKey="google-calendar-api")
@Dependent
@RegisterProvider(AccessTokenRequestReactiveFilter.class)
@Path("/calendars/primary")
public interface GoogleCalendarClient {
@POST
@Path("events")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
Uni<String> addEvent(Event event);
public static class Event {
public String summary;
public String kind = "calendar#event";
public Time start;
public Time end;
}
@NoArgsConstructor
public static class Time {
public String dateTime;
public String timeZone = "Europe/CET";
public Time(String value) {
dateTime = value;
}
}
} And configured it as follows: quarkus.oidc.auth-server-url=http://localhost:8545/realms/quarkus-realm
quarkus.keycloak.devservices.realm-path=keycloak.json
quarkus.oidc-client.auth-server-url=http://localhost:8545/realms/quarkus-realm
quarkus.oidc-client.client-id=origin-client
quarkus.oidc-client.credentials.secret=secret
quarkus.oidc-client.scopes=profile,openid,email
quarkus.oidc-client.grant.type=exchange
quarkus.oidc-client.google-calendar-api.grant.type=exchange
google-calendar-api/mp-rest/url=https://www.googleapis.com/calendar/v3
google-calendar-api/mp-rest/scope=javax.inject.Singleton
quarkus.oidc-client.early-tokens-acquisition=true
quarkus.oidc-client.grant-options.exchange.audience=origin-client
quarkus.oidc-token-propagation-reactive.client-name=google-calendar-api
quarkus.oidc-token-propagation-reactive.exchange-token=true The problem I'm getting is, when I use AccessTokenRequestReactiveFilter to register the provider in my rest client, this client can't be initialized:
How should I register the Rest Client? Since all the configuration in application.properties is being done. Or is this error caused by a wrong configuration for the token-exchange? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
/cc @pedroigor (keycloak), @sberyozkin (keycloak) |
Beta Was this translation helpful? Give feedback.
-
After several tests, I found out where my mistakes were and fixed them. |
Beta Was this translation helpful? Give feedback.
Hi @sberyozkin
I was able to exchange to a Google token using Keycloak. To do this, I created a Realm, and inside it I created a client and an identity provider (Google). Inside the Identity Provider, I enabled the Token Exchange permission and added a Policy to allow the Client that was created to perform the Token Exchange.
With this configuration done, I set up my Quarkus application as follows: