Clients

https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html#_clients

One should not be confused between client_id and the UUID a client has. Therefor this section will refer to variable names containing the UUID of a client as client_uuid.

class keycloak_admin_aio._resources.clients.Clients

Provides the Keycloak clients resource.

from keycloak_admin_aio import KeycloakAdmin, ClientRepresentation

kc: KeycloakAdmin  # must be instantiated
get_url()

Get the resource’s url.

Return type:

str

async create(client_representation)

Create a client.

client_representation = ClientRepresentation(name="client-name")
client_uuid: str = await kc.clients.create(client_representation)
Parameters:

client_representation (ClientRepresentation)

Return type:

str

async get(client_id=None, first=None, max=None, q=None, search=False, viewable_only=False)

Get clients.

clients: list[ClientRepresentation] = await kc.clients.get()
Parameters:
  • client_id (str | None)

  • first (int | None)

  • max (int | None)

  • q (str | None)

  • search (bool | None)

  • viewable_only (bool | None)

Return type:

list[ClientRepresentation]

Clients by id

class keycloak_admin_aio._resources.clients.by_id.ClientsById

Clients by UUID.

from keycloak_admin_aio import KeycloakAdmin, ClientRepresentation

kc: KeycloakAdmin  # must be instantiated
client_uuid: str
get_url()

Get the resource’s url.

Return type:

str

async get()

Get a client by UUID.

client_representation: ClientRepresentation = await kc.clients.by_id(client_uuid).get()
Return type:

ClientRepresentation

async update(client_representation)

Update a client by UUID.

client_representation = ClientRepresentation(name="client-name")
await kc.clients.by_id(client_uuid).update(client_representation)
Parameters:

client_representation (ClientRepresentation)

async delete()

Delete a client by UUID.

await kc.clients.by_id(client_uuid).delete()

Default client scopes for a client by id

class keycloak_admin_aio._resources.clients.by_id.default_client_scopes.ClientsByIdDefaultClientScopes

Default client scopes for clients by UUID.

from keycloak_admin_aio import KeycloakAdmin, ClientScopeRepresentation

kc: KeycloakAdmin  # must be instantiated
client_uuid: str
get_url()

Get the resource’s url.

Return type:

str

async get()

Get default clients scopes for a client by UUID.

client_scope_resource = kc.clients.by_id(client_uuid)
client_scope_representations: list[
    ClientScopeRepresentation
] = await client_scope_resource.default_client_scopes.get()
Return type:

list[ClientScopeRepresentation]

Default client scope by id for a client by id

class keycloak_admin_aio._resources.clients.by_id.default_client_scopes.by_id.ClientsByIdDefaultClientScopesById

Client scopes by id for a client by UUID.

from keycloak_admin_aio import KeycloakAdmin

kc: KeycloakAdmin  # must be instantiated
client_uuid: str
client_scope_id: str  # uuid
get_url()

Get the resource’s url.

Return type:

str

async create()

Add a client scope by id to a client by id.

await kc.clients.by_id(client_uuid).default_client_scopes.by_id(client_scope_id).create()
async delete()

Remove a client scope by id from a client by id.

await kc.clients.by_id(client_uuid).default_client_scopes.by_id(client_scope_id).delete()

User sessions for client by id

class keycloak_admin_aio._resources.clients.by_id.user_sessions.ClientsByIdUserSessions

User sessions for clients by id.

from keycloak_admin_aio import KeycloakAdmin, UserSession

kc: KeycloakAdmin  # must be instantiated
client_uuid: str
get_url()

Get the resource’s url.

Return type:

str

async get(first=None, max=None)

Get user sessions for a client.

user_sessions: lists[UserSession] = await kc.clients.by_id(client_uuid).user_sessions.get()
Parameters:
  • first (int | None)

  • max (int | None)

Return type:

list[UserSession]