You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add ability to use an HTTP client from a custom SPI #31096
Hi there. I'd like to have an example documented in Keycloak's docs or to ask for a high-level HTTP client inclusion to the Keycloak distribution that users can use when developing their custom SPIs to invoke microservices. Keycloak includes a dependency that uses HTTP but to connect to external Keycloak instances, this is not what I'm trying to achieve.
Very old Keycloak versions allow to use an HTTP client to call microservices without much hassle. But Quarkus-based Keycloak distributions make it really hard to use an HTTP client from a custom SPI (although there is a dependency to talk to external Keycloak instances).
The Keycloak documentation doesn't include an example for this, and the Quarkus documentation is stale and a mess, as they have migrated packages' names a couple of times and it's not clear which one is the right approach.
I spent a lot of hours trying to use a simple HTTP client from a custom SPI, but this has been quite challenging. I don't want to use the built-in HTTP client that comes with Java because of its verbosity, I would like to use a higher-level one.
Details
Please add an example of how to use a high-level HTTP client to the custom SPI (similar to what has been done with JPA) if one is already available, or consider including one to the Keycloak distribution so that we can use it.
Reacted by Gabriel Padilha Santos, Paul Brejla, Dean, jfloresi-vn, keycloak-github-bot and Alexander
I was able to use a workaround to use an HTTP client in the end, and yes, it would be nice to have some official documentation.
On the other hand, and if you guys are open to feedback, it would be awesome if developers could easily use at least the Quarkus HTTP client or similar as part of their custom SPIs. The rationale behind this request is that it makes the SPI code clearer and less verbose.
Do you want to explore the exension route as part of the triage of this issue? If so, I'll leave the prioritization up to you. My intent intially is just to clean up the backlog.
Now, my understanding is that dependency injection doesn't work with SPI (and trying to do so would lead to an exception), but I could get the client programmatically from my service doing something like:
finalvarexternalHttpCient = QuarkusRestClientBuilder.newBuilder() // Alternatively, RestClientBuilder could be used
.baseUri(URI.create("http://localhost:8080/api"))
.build(ExternalHttpService.class);
That would, in my opinion, dramatically simplify the code.
Workaround
I created one SimpleHttp per endpoint I wanted to call, for example SimpleHttp.doGet("http://localhost:8080/api/users", keycloakSession). While this works, it adds a lot of boilerplate code.
Activity
[-]Add ability to use a HTTP client from a custom SPI[/-][+]Add ability to use an HTTP client from a custom SPI[/+]shawkins commentedon Jul 31, 2025
See #30949 (comment) in particular
from a KeycloakSession using:
session.getProvider(HttpClientProvider.class).getHttpClient()Changing this to a documentation issue.
Nahuel92 commentedon Jul 31, 2025
Hi @shawkins , thanks for your answer!
I was able to use a workaround to use an HTTP client in the end, and yes, it would be nice to have some official documentation.
On the other hand, and if you guys are open to feedback, it would be awesome if developers could easily use at least the Quarkus HTTP client or similar as part of their custom SPIs. The rationale behind this request is that it makes the SPI code clearer and less verbose.
Thanks again.
mabartos commentedon Aug 4, 2025
@shawkins Could you please set the priority of the issue? Thanks!
mabartos commentedon Aug 4, 2025
@Nahuel92 Thanks for the comment!
It'd be good to know what exactly do you need or what would be the best.
I tried to capture it even here to properly test it: mabartos/keycloak-quarkus-extensions#11
shawkins commentedon Aug 4, 2025
Do you want to explore the exension route as part of the triage of this issue? If so, I'll leave the prioritization up to you. My intent intially is just to clean up the backlog.
mabartos commentedon Aug 4, 2025
@shawkins I'll set the priority of this bug to
normalto capture the docs issue.Using other clients in extension is out of scope, and I'll try to experiment with it a little bit.
7 remaining items
Nahuel92 commentedon Aug 4, 2025
Hi @mabartos, thanks for the quick answer!
Following I share what I believe the ideal solution should be, and the workaround I used.
Ideal solution
I would like to do something like this:
Now, my understanding is that dependency injection doesn't work with SPI (and trying to do so would lead to an exception), but I could get the client programmatically from my service doing something like:
Then, to get all users:
That would, in my opinion, dramatically simplify the code.
Workaround
I created one
SimpleHttpper endpoint I wanted to call, for exampleSimpleHttp.doGet("http://localhost:8080/api/users", keycloakSession). While this works, it adds a lot of boilerplate code.Thanks!