Roles

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

class keycloak_admin_aio._resources.roles.Roles

Provides the Keycloak role 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 create(role_representation)

Create a role. Returns the role name.

role_representation = RoleRepresentation(name="some-role")
role_name: str = await kc.roles.create(role_representation)
Parameters:

role_representation (RoleRepresentation)

Return type:

str

async get(brief_representation=None, first=None, max=None, search=None)

Get roles.

roles: list[RoleRepresentation] = kc.roles.get()
Parameters:
  • brief_representation (bool | None)

  • first (int | None)

  • max (int | None)

  • search (str | None)

Return type:

list[RoleRepresentation]

Roles by id

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

class keycloak_admin_aio._resources.roles.by_id.RolesById

Provides roles by id.

from keycloak_admin_aio import KeycloakAdmin, RoleRepresentation

kc: KeycloakAdmin  # needs to be instantiated
role_id: str  # uuid
get_url()

Get the resource’s url.

Return type:

str

async get()

Get a role by id.

role: RoleRepresentation = await kc.roles.by_id(role_id).get()
Return type:

RoleRepresentation

async update(role_representation)

Update a role by id.

role_representation = RoleRepresentation(name="role-name")
await kc.roles.by_id(role_id).update(role_representation)
Parameters:

role_representation (RoleRepresentation)

async delete()

Delete a role by id.

await kc.roles.by_id(role_id).delete()

Composite roles for a role by id

class keycloak_admin_aio._resources.roles.by_id.composites.RolesByIdComposites

Get composites for a role by id.

from keycloak_admin_aio import KeycloakAdmin, RoleRepresentation

kc: KeycloakAdmin  # needs to be instantiated
role_id: str  # uuid
get_url()

Get the resource’s url.

Return type:

str

async create(composite_roles)

Create composites for a role by id.

role_representations: list[RoleRepresentation] = []  # needs to be populated
await kc.roles.by_id(role_id).composites.create(role_representations)
Parameters:

composite_roles (list[RoleRepresentation])

async get()

Get composites for a role by id.

composites: list[RoleRepresentation] = await kc.roles.by_id(role_id).composites.get()
Return type:

list[RoleRepresentation]

async delete(composite_roles)

Delete composites for a role by id.

role_representations: list[RoleRepresentation] = []  # needs to be populated
await kc.roles.by_id(role_id).composites.delete(role_representations)
Parameters:

composite_roles (list[RoleRepresentation])

Roles by name

class keycloak_admin_aio._resources.roles.by_name.RolesByName

Provides roles by name.

from keycloak_admin_aio import KeycloakAdmin, RoleRepresentation

kc: KeycloakAdmin  # needs to be instantiated
role_name: str
get_url()

Get the resource’s url.

Return type:

str

async get()

Get role by name.

role: RoleRepresentation = await kc.roles.by_name(role_name).get()
Return type:

RoleRepresentation

async update(role_representation)

Update role by name.

role_representation = RoleRepresentation(name="role-name")
await kc.roles.by_name(role_name).update(role_representation)
Parameters:

role_representation (RoleRepresentation)

async delete()

Delete role by name.

await kc.roles.by_name(role_name).delete()

Composite roles for a role by name

class keycloak_admin_aio._resources.roles.by_name.composites.RolesByNameComposites

Get composites for a role by name.

from keycloak_admin_aio import KeycloakAdmin, RoleRepresentation

kc: KeycloakAdmin  # needs to be instantiated
role_name: str
get_url()

Get the resource’s url.

Return type:

str

async create(composite_roles)

Create composites for a role by name.

role_representations: list[RoleRepresentation] = []  # needs to be populated
await kc.roles.by_name(role_name).composites.create(role_representations)
Parameters:

composite_roles (list[RoleRepresentation])

async get()

Get composites for a role by id.

composites: list[RoleRepresentation] = await kc.roles.by_name(role_name).composites.get()
Return type:

list[RoleRepresentation]

async delete(composite_roles)

Delete composites for a role by id.

role_representations: list[RoleRepresentation] = []  # needs to be populated
await kc.roles.by_name(role_name).composites.delete(role_representations)
Parameters:

composite_roles (list[RoleRepresentation])