How can I get other users info(username, firstname) by id? [Keycloak]

You can use the Admin REST API. The detailed description of the relevant API is available here. Also you can use the JAVA wrapper API. Please find couple of examples below.

Example 1, REST:

Get an access token:

curl \
  -d "client_id=admin-cli" \
  -d "username=admin" \
  -d "password=secret" \
  -d "grant_type=password" \

Get all users:

curl \
  -H "Authorization: bearer eyJhbGciOiJSUzI...." \

Sample output:


Get a user based by user id:

curl \
  -H "Authorization: bearer eyJhbGciOiJSU...." \

Example 2, JAVA API:

Get a used based on used ID:

public class TestUserAccess {

  private static final String SERVER_URL = "http://localhost:8080/auth";
  private static final String REALM = "master";
  private static final String USERNAME = "admin";
  private static final String PASSWORD = "secret";
  private static final String CLIENT_ID = "admin-cli";

  public static void main(String[] args) {

    Keycloak keycloak = KeycloakBuilder
        .resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build())

    UsersResource usersResource = keycloak.realm(REALM).users();
    UserResource userResource = usersResource.get("08afb701-fae5-40b4-8895-e387ba1902fb");

The relevant dependencies for the example above are (please note that the versions might not be up-to-date):

dependencies {
    compile group: 'org.keycloak', name: 'keycloak-admin-client', version: '3.3.0.CR2'
    compile group: 'org.jboss.resteasy', name: 'resteasy-jaxrs', version: '3.1.4.Final'
    compile group: 'org.jboss.resteasy', name: 'resteasy-client', version: '3.1.4.Final'
    compile group: 'org.jboss.resteasy', name: 'resteasy-jackson2-provider', version: '3.1.4.Final'

The is simple method as well, because in above answer all the user info is getting fetched which is not the proper way because in case thousands of users it will be heavy call.

so just pass username as query parameter

GET: http://localhost:8080/auth/admin/realms/{real-name}/users?username=testUser

make sure you user admin access token for the call