Skip to content

Add ability to use an HTTP client from a custom SPI #31096

Description

@Nahuel92

Description

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.

Discussion

I couldn't solve my issue:

#30949

Motivation

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.

Activity

  1. added
    kind/feature
    on Jul 7, 2024
  2. changed the title [-]Add ability to use a HTTP client from a custom SPI[/-] [+]Add ability to use an HTTP client from a custom SPI[/+] on Jul 7, 2024
  3. shawkins commented on Jul 31, 2025

    @shawkins
    Contributor

    See #30949 (comment) in particular
    from a KeycloakSession using: session.getProvider(HttpClientProvider.class).getHttpClient()

    Changing this to a documentation issue.

  4. added
    area/docs
    kind/bug
    and removed
    kind/feature
    on Jul 31, 2025
  5. Nahuel92 commented on Jul 31, 2025

    @Nahuel92
    Author

    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.

  6. mabartos commented on Aug 4, 2025

    @mabartos
    Member

    @shawkins Could you please set the priority of the issue? Thanks!

  7. mabartos commented on Aug 4, 2025

    @mabartos
    Member

    @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

  8. shawkins commented on Aug 4, 2025

    @shawkins
    Contributor

    @shawkins Could you please set the priority of the issue? Thanks!
    I tried to capture it even here to properly test it: mabartos/keycloak-quarkus-extensions#11

    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.

  9. mabartos commented on Aug 4, 2025

    @mabartos
    Member

    @shawkins I'll set the priority of this bug to normal to capture the docs issue.

    Using other clients in extension is out of scope, and I'll try to experiment with it a little bit.

  10. 7 remaining items

  11. Nahuel92 commented on Aug 4, 2025

    @Nahuel92
    Author

    @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

    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:

    @Path("/users")
    public interface ExternalHttpService {
        @GET
        MyDTO getById(@QueryParam("id") String id);
    
        @GET
        Set<MyDTO> getAll();
    }
    
    record MyDTO(String id, String name, String lastName, String email /*, other fields */) {
    }

    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:

    final var externalHttpCient = QuarkusRestClientBuilder.newBuilder()    // Alternatively, RestClientBuilder could be used
                .baseUri(URI.create("http://localhost:8080/api"))
                .build(ExternalHttpService.class);

    Then, to get all users:

    // ...
    final var allUsers = externalHttpCient.getAll();
    // ...

    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.

    Thanks!

  12. added this to the 26.5.0 milestone on Sep 30, 2025
  13. added theissue type on Oct 2, 2025
  14. added
    kind/enhancement
    and removed
    kind/bug
    on Dec 16, 2025
  15. changed the issue type fromtoon Dec 16, 2025
  16. modified the milestones: 26.5.0, Future on Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/docskind/enhancementteam/cloud-native

    Fields

    Value

    None yet

    Effort

    None yet

    Votes

    None yet

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions