Auth0Client.Management.Role (auth0_client v1.1.0)

Copy Markdown View Source

A module representing roles on Auth0.

A role is a named bundle of permissions. Grant it to a user with Auth0Client.Management.User.assign_roles/2; there is no endpoint for removing a user from a role on this side, so use Auth0Client.Management.User.remove_roles/2.

https://auth0.com/docs/api/management/v2/roles

Summary

Functions

Assigns groups to a role

Adds permissions to a role.

Assigns users to a role

Gets all the roles

Creates a role. name is required; description is optional.

Deletes a role. Users assigned to it lose the permissions it granted.

Gets a single role

Gets the groups a role is assigned to.

Gets the permissions a role grants

Removes groups from a role

Removes permissions from a role

Updates a role's name or description

Gets the users assigned to a role.

Functions

add_groups(id, group_ids)

Assigns groups to a role

iex> Auth0Client.Management.Role.add_groups("rol_abc123", ["grp_1", "grp_2"])

add_permissions(id, permissions)

Adds permissions to a role.

Accepts either the documented map form or {api_identifier, permission_name} tuples.

iex> Auth0Client.Management.Role.add_permissions("rol_abc123", [{"https://api.example.com", "read:users"}])
iex> Auth0Client.Management.Role.add_permissions("rol_abc123", [%{resource_server_identifier: "https://api.example.com", permission_name: "read:users"}])

add_users(id, user_ids)

Assigns users to a role

iex> Auth0Client.Management.Role.add_users("rol_abc123", ["auth0|user1", "auth0|user2"])

all(params \\ %{})

Gets all the roles

Supports name_filter to search by name, and page / per_page / include_totals for pagination.

iex> Auth0Client.Management.Role.all()
iex> Auth0Client.Management.Role.all(name_filter: "admin", per_page: 50)

create(body)

Creates a role. name is required; description is optional.

iex> Auth0Client.Management.Role.create(%{name: "admin", description: "Can do anything"})

delete(id)

Deletes a role. Users assigned to it lose the permissions it granted.

iex> Auth0Client.Management.Role.delete("rol_abc123")

get(id)

Gets a single role

iex> Auth0Client.Management.Role.get("rol_abc123")

groups(id, params \\ %{})

Gets the groups a role is assigned to.

Uses checkpoint pagination only — from and take.

iex> Auth0Client.Management.Role.groups("rol_abc123")

permissions(id, params \\ %{})

Gets the permissions a role grants

iex> Auth0Client.Management.Role.permissions("rol_abc123")
iex> Auth0Client.Management.Role.permissions("rol_abc123", per_page: 50)

remove_groups(id, group_ids)

Removes groups from a role

iex> Auth0Client.Management.Role.remove_groups("rol_abc123", ["grp_1"])

remove_permissions(id, permissions)

Removes permissions from a role

iex> Auth0Client.Management.Role.remove_permissions("rol_abc123", [{"https://api.example.com", "read:users"}])

update(id, body)

Updates a role's name or description

iex> Auth0Client.Management.Role.update("rol_abc123", %{description: "Updated"})

users(id, params \\ %{})

Gets the users assigned to a role.

Supports offset pagination (page / per_page) and checkpoint pagination (from / take). Auth0 requires checkpoint pagination past 1000 records.

iex> Auth0Client.Management.Role.users("rol_abc123")
iex> Auth0Client.Management.Role.users("rol_abc123", take: 50)