Class KeycloakBuilder

java.lang.Object
org.keycloak.admin.client.KeycloakBuilder

public class KeycloakBuilder extends Object
Provides a Keycloak client builder with the ability to customize the underlying RESTEasy client used to communicate with the Keycloak server.

Example usage with a connection pool size of 20:

   Keycloak keycloak = KeycloakBuilder.builder()
     .serverUrl("https://sso.example.com/auth")
     .realm("realm")
     .username("user")
     .password("pass")
     .clientId("client")
     .clientSecret("secret")
     .resteasyClient(new ResteasyClientBuilderImpl()
                 .connectionPoolSize(20)
                 .build()
                 .register(org.keycloak.admin.client.JacksonProvider.class, 100))
     .build();
 

Example usage with grant_type=client_credentials

   Keycloak keycloak = KeycloakBuilder.builder()
     .serverUrl("https://sso.example.com/auth")
     .realm("example")
     .grantType(OAuth2Constants.CLIENT_CREDENTIALS)
     .clientId("client")
     .clientSecret("secret")
     .build();
 
Author:
Scott Rossillo
See Also:
  • Client
  • Method Details

    • serverUrl

      public KeycloakBuilder serverUrl(String serverUrl)
    • realm

      public KeycloakBuilder realm(String realm)
    • grantType

      public KeycloakBuilder grantType(String grantType)
    • username

      public KeycloakBuilder username(String username)
    • password

      public KeycloakBuilder password(String password)
    • clientId

      public KeycloakBuilder clientId(String clientId)
    • scope

      public KeycloakBuilder scope(String scope)
    • clientSecret

      public KeycloakBuilder clientSecret(String clientSecret)
    • resteasyClient

      public KeycloakBuilder resteasyClient(jakarta.ws.rs.client.Client resteasyClient)
      Custom instance of resteasy client. Please see the documentation for additional details regarding the compatibility
      Parameters:
      resteasyClient - Custom RestEasy client
      Returns:
      admin client builder
    • authorization

      public KeycloakBuilder authorization(String auth)
    • useDPoP

      public KeycloakBuilder useDPoP(boolean useDPoP)
      Parameters:
      useDPoP - If true, then admin-client will add DPoP proofs to the token-requests and to the admin REST API requests. DPoP feature must be enabled on Keycloak server side to work properly. It is false by default.
      Returns:
      admin client builder
    • build

      public Keycloak build()
      Builds a new Keycloak client from this builder.
    • builder

      public static KeycloakBuilder builder()
      Returns a new Keycloak builder.