Users¶
https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html#_users
- class keycloak_admin_aio._resources.users.Users¶
Provides the Keycloak user resource.
from keycloak_admin_aio import KeycloakAdmin, UserRepresentation kc: KeycloakAdmin # needs to be instantiated
- get_url()¶
Get the resource’s url.
- Return type:
str
- async get(brief_representation=None, first=None, max=None, search=None, email=None, email_verified=None, enabled=None, exact=None, first_name=None, last_name=None, idp_alias=None, idp_user_id=None, username=None)¶
Get users.
users: list[UserRepresentation] = await kc.users.get()
- Parameters:
brief_representation (bool | None)
first (int | None)
max (int | None)
search (str | None)
email (str | None)
email_verified (bool | None)
enabled (bool | None)
exact (bool | None)
first_name (str | None)
last_name (str | None)
idp_alias (str | None)
idp_user_id (str | None)
username (str | None)
- Return type:
list[UserRepresentation]
- async create(user_representation)¶
Create user.
user_representation = UserRepresentation(email="user@domain.com") user_id: str = await kc.users.create(user_representation)
- Parameters:
user_representation (UserRepresentation)
- Return type:
str
- async count(search=None, email=None, email_verified=None, exact=None, first_name=None, last_name=None, username=None)¶
User count.
user_count: int = await kc.users.count()
- Parameters:
search (str | None)
email (str | None)
email_verified (bool | None)
exact (bool | None)
first_name (str | None)
last_name (str | None)
username (str | None)
- Return type:
int
Users by id¶
- class keycloak_admin_aio._resources.users.by_id.UsersById¶
Provides the Keycloak users by id resource.
from keycloak_admin_aio import KeycloakAdmin, UserRepresentation kc: KeycloakAdmin # needs to be instantiated user_id: str # uuid
- get_url()¶
Get the resource’s url.
- Return type:
str
- async get()¶
Get user by id.
user: UserRepresentation = await kc.users.by_id(user_id).get()
- Return type:
- async update(user_representation)¶
Update user by id.
user_representation = UserRepresentation(first_name="New name") await kc.users.by_id(user_id).update(user_representation)
- Parameters:
user_representation (UserRepresentation)
- async delete()¶
Delete user by id.
await kc.users.by_id(user_id).delete()
Execute actions email¶
- class keycloak_admin_aio._resources.users.by_id.execute_actions_email.UsersByIdExecuteActionsEmail¶
Provides the Keycloak user execute actions email resource.
from keycloak_admin_aio import KeycloakAdmin kc: KeycloakAdmin # needs to be instantiated user_id: str
- get_url()¶
Get the resource’s url.
- Return type:
str
- async send_email(actions, client_id=None, lifespan=None, redirect_uri=None)¶
Send email to user.
await kc.users.by_id(user_id).execute_actions_email.send_email()
- Parameters:
actions (list[str])
client_id (str | None)
lifespan (int | None)
redirect_uri (str | None)
Group memberships¶
- class keycloak_admin_aio._resources.users.by_id.groups.UsersByIdGroups¶
Provides the Keycloak groups resource for users by id
from keycloak_admin_aio import KeycloakAdmin, GroupRepresentation kc: KeycloakAdmin # needs to be instantiated user_id: str # uuid
- get_url()¶
Get the resource’s url.
- Return type:
str
- async get(first=None, max=None, search=None, brief_representation=True)¶
Get the user’s groups.
groups: list[GroupRepresentation] = await kc.users.by_id(user_id).groups.get()
- Parameters:
first (int | None)
max (int | None)
search (str | None)
brief_representation (bool)
- Return type:
list[GroupRepresentation]
- async count(search=None)¶
Get the number of groups the user belongs to.
membership_count: int = await kc.users.by_id(user_id).groups.count()
- Parameters:
search (str | None)
- Return type:
int
Role mappings¶
- class keycloak_admin_aio._resources.users.by_id.role_mappings.UsersByIdRoleMappings¶
Provides the role mappings for a user.
from keycloak_admin_aio import KeycloakAdmin, MappingsRepresentation kc: KeycloakAdmin # needs to be instantiated user_id: str # uuid
- get_url()¶
Get the resource’s url.
- Return type:
str
- async get()¶
Get the role mappings for a user.
mappings: MappingsRepresentation = await kc.users.by_id(user_id).role_mappings.get()
- Return type:
Realm role mappings¶
- class keycloak_admin_aio._resources.users.by_id.role_mappings.realm.UsersByIdRoleMappingsRealm¶
Provides the realm role mappings for users.
from keycloak_admin_aio import KeycloakAdmin, RoleRepresentation kc: KeycloakAdmin # needs to be instantiated user_id: str # uuid
- get_url()¶
Get the resource’s url.
- Return type:
str
- async get()¶
Get realm role mappings for a user.
roles: list[RoleRepresentation] = await kc.users.by_id(user_id).role_mappings.realm.get()
- Return type:
list[RoleRepresentation]
- async create(role_representations)¶
Create realm role mappings for a user.
roles list[RoleRepresentation] = [] # needs to be populated await kc.users.by_id(user_id).role_mappings.realm.create(roles)
- Parameters:
role_representations (list[RoleRepresentation])
- async delete(role_representations)¶
Delete realm roles mappings for a user.
roles: list[RoleRepresentation] = [] # needs to be populated await kc.users.by_id(user_id).role_mappings.realm.delete(roles)
- Parameters:
role_representations (list[RoleRepresentation])
- async available()¶
Get available roles which can be mapped to the user.
roles: list[RoleRepresentation] = await kc.users.by_id(user_id).role_mappings.realm.available()
- Return type:
list[RoleRepresentation]
- async composite()¶
Get composed realm roles for a user.
roles: list[RoleRepresentation] = await kc.users.by_id(user_id).role_mappings.realm.composite()
- Return type:
list[RoleRepresentation]