is there a smaple quarkus project with multiple named OidcClients to call multiple service calls?

368 Views Asked by At

am looking for a sample quarkus reactive project with multiple OidcClients to make multiple service calls?

Eg: DemoProject wants to call service A, B, C, D. DemoProject used keycloak authorization with grant type as password. Service A has OidcClientA, service B has OidcClientB, service C has OidcClientC, Service D has OidcClientD. How can we simply inject OidcClient into a specific service and fetching the specific token, authorization header to a specific service automatically?

Quarkus Documentation: https://quarkus.io/guides/security-openid-connect-client

2

There are 2 best solutions below

0
On

I couldn't find any sample project, but i think that you just need to configure the named clients in your properties files and they will be accesible through the OidcClients class.

Here you can find more information.

If you are going to consume each service individually I would suggest you create a facade or a service in front of the rest client to deal with this complexity or maybe a filter for each service rest-client

0
On

This is completely possible, and actually very easy. The problem is that is not properly documented; i had to dig into quarkus source code to find it.

In your application.properties, just add the client-name you want after quarkus.oidc-client.

For example, before named client:

quarkus.oidc-client.auth-server-url=<url>

Will then become

quarkus.oidc-client.<client-name>.auth-server-url=<url>

Then in the code, where Tokens or OidcClient is injected, just add @NamedOidcClient("").

And that's it!

I will post with a working git later.