Skip to content

ClientsResource.findByClientId(String) should return a single item #39851

Closed as not planned
Closed as not planned

Description

@Lunatix01

Description

We have such a method org.keycloak.admin.client.resource.ClientsResource.findByClientId(String) that should return a single item, but it returns a List of ClientRepresentation.

Discussion

No response

Motivation

Cleaner, more readable, removing ambiguity

Details

We have such a method org.keycloak.admin.client.resource.ClientsResource.findByClientId(String) that should return a single item, but it returns a List of ClientRepresentation, We should note that clientId is unique, so it creates ambiguity. As an enhancement, it's nice to have a method like this:

    @GET
    @Path("by-client-id")
    @Produces(MediaType.APPLICATION_JSON)
    ClientRepresentation findClientByClientId(@QueryParam("clientId") String clientId);

Note

By adding this, we should mark this method as deprecated List<ClientRepresentation> findByClientId(@QueryParam("clientId") String clientId);

Since org.keycloak.admin.client.resource.ClientsResource is an interface, probably we need to create a new method in org.keycloak.services.resources.admin.ClientsResource to return ClientRepresentation

This enhancement makes it easier to understand since it will just do this job, also, we can have a better error handling for a single record by throwing errors like {NOT_FOUND, BAD_REQUEST, FORBIDDEN}

I'm preparing a pull request for this change if this enhancement gets approved by a comment

Here is an issue from keycloak-client repo keycloak/keycloak-client#155

Activity

  1. added
    kind/enhancement
    on May 20, 2025
  2. added
    area/admin/client-java
    and removed on Oct 2, 2025
  3. Abhikaravate commented on Jan 28, 2026

    @Abhikaravate

    Hi maintainers,

    I would like to work on this issue.

    I understand the goal is to refactor findByClientId to return a single item (or Optional) since client IDs are unique, removing the ambiguity of returning a List.

    I will analyze the current implementation in ClientsResource and submit a PR. Please assign this to me

  4. shawkins commented on Jan 28, 2026

    @shawkins
    Contributor

    @Abhikaravate thank you for your interest, but there is already a PR open for this issue.

  5. shawkins commented on Mar 13, 2026

    @shawkins
    Contributor

    Marking as out-of-date - an attempt at a PR did not garner sufficient interest for inclusion.

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

    action/priority-lowarea/admin/client-javakind/enhancementteam/core-shared

    Fields

    Value

    None yet

    Effort

    None yet

    Votes

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions