Auth0Client.Management.User (auth0_client v1.1.0)

Copy Markdown View Source

A module representing users on Auth0

Summary

Functions

Gets all the users

Assigns permissions to a user directly.

Assigns roles to a user. Scopes: update:users

Gets a single authentication method

Lists a user's authentication methods — the factors they can log in with.

Finds users by email address.

Clears a user's risk assessments, so past signals stop influencing their next login.

Lists accounts the user has connected from other providers. Uses checkpoint pagination.

Creates a user for the specified connection

Adds an authentication method. type is required — phone, email, totp or webauthn-roaming.

Deletes a user with a give user id

Deletes a single authentication method

Deletes all users MFA authentication methods. Scopes: delete:authentication_methods

Deletes all of a user's MFA authenticators, forcing re-enrollment

Deletes a user's multifactor provider

Deletes all of a user's refresh tokens. Answers 202.

Deletes all of a user's sessions, signing them out everywhere.

Lists the roles that grant a user a given permission, answering "why does this user have this permission?".

Lists every permission a user has, whether granted directly, through a role, or through a group.

Lists the groups that grant a user a given role, answering "why does this user have this role?".

Lists every role a user has, whether assigned directly or inherited through a group.

Gets the user's first confirmed Guardian MFA enrollment.

Gets a specific user record with a given user id

Lists the groups a user belongs to

Invalidates every remembered browser, so the user is prompted for MFA again

Links the account specified in the body to the given user_id param

Get a user's log

Lists the organizations a user belongs to. Scopes: read:users read:organizations

Lists the permissions granted to a user directly, ignoring any that come from a role. Use effective_permissions/2 for the full picture. Scopes: read:users

Lists a user's refresh tokens. Uses checkpoint pagination.

Removes current Guardain recovery code and generates new one

Removes permissions from a user. Scopes: update:users

Removes roles from a user. Scopes: update:users

Replaces every authentication method the user has.

Revokes a user's access — sessions and refresh tokens together. Answers 202.

List the roles associated with a user. Scopes: read:users read:roles

Lists a user's active sessions. Uses checkpoint pagination.

Unlinks an identity from the target user, and it becomes a separated user again.

Updates a user's information given a user id

Updates an authentication method's name or preference

Functions

all(params \\ %{})

Gets all the users

Defaults to the v3 search engine, which is the only one Auth0 still supports. Pass an explicit search_engine to override it.

v3 search differs from v2 in ways that silently return nothing rather than erroring:

  • .raw sub-fields are gone — query the field directly

  • connection became identities.connection

  • matching is case-sensitive

  • results cap at 1,000 records; use Auth0Client.Management.Job.users_exports/1 for anything larger

    iex> Auth0Client.Management.User.all() iex> Auth0Client.Management.User.all(fields: "name", q: "app_metadata.admin:'true'")

assign_permissions(user_id, permissions)

Assigns permissions to a user directly.

Accepts either the documented map form or {api_identifier, permission_name} tuples. Scopes: update:users

iex> Auth0Client.Management.User.assign_permissions("auth0|23423", [{"https://api.example.com", "read:users"}])

assign_roles(user_id, role_ids)

Assigns roles to a user. Scopes: update:users

iex> Auth0Client.Management.User.assign_roles("auth0|23423", ["rol_abc123"])

authentication_method(user_id, method_id)

Gets a single authentication method

iex> Auth0Client.Management.User.authentication_method("auth0|23423", "aum_1")

authentication_methods(user_id, params \\ %{})

Lists a user's authentication methods — the factors they can log in with.

iex> Auth0Client.Management.User.authentication_methods("auth0|23423")

by_email(email, params \\ %{})

Finds users by email address.

This is an exact, case-insensitive match on the identity, and it is usually what you want. all/1 goes through the v3 search engine instead, which is case-sensitive and caps at 1,000 records — worth avoiding when you simply have an address and want the user.

Returns a list, because one address can belong to several identities across connections.

iex> Auth0Client.Management.User.by_email("someone@example.com")
iex> Auth0Client.Management.User.by_email("someone@example.com", fields: "user_id,email")

clear_risk_assessments(user_id, body \\ %{})

Clears a user's risk assessments, so past signals stop influencing their next login.

iex> Auth0Client.Management.User.clear_risk_assessments("auth0|23423")
iex> Auth0Client.Management.User.clear_risk_assessments("auth0|23423", %{assessors: ["NewDevice"]})

connected_accounts(user_id, params \\ %{})

Lists accounts the user has connected from other providers. Uses checkpoint pagination.

iex> Auth0Client.Management.User.connected_accounts("auth0|23423")

create(connection, body \\ %{})

Creates a user for the specified connection

iex> Auth0Client.Management.User.create("test_connection", %{email: "test.user@email.com", username: "test_user_name"})

create_authentication_method(user_id, body)

Adds an authentication method. type is required — phone, email, totp or webauthn-roaming.

iex> Auth0Client.Management.User.create_authentication_method("auth0|23423", %{type: "totp", totp_secret: "..."})

delete(user_id)

Deletes a user with a give user id

iex> Auth0Client.Management.User.delete("auth0|some_user_id")

delete_authentication_method(user_id, method_id)

Deletes a single authentication method

iex> Auth0Client.Management.User.delete_authentication_method("auth0|23423", "aum_1")

delete_authentication_methods(user_id)

Deletes all users MFA authentication methods. Scopes: delete:authentication_methods

iex> Auth0Client.Management.User.delete_authentication_methods("auth0|23423")

delete_authenticators(user_id)

Deletes all of a user's MFA authenticators, forcing re-enrollment

iex> Auth0Client.Management.User.delete_authenticators("auth0|23423")

delete_mfprovider(user_id, provider)

Deletes a user's multifactor provider

iex> Auth0Client.Management.User.delete_mfprovider("auth0|23423", "duo")

delete_refresh_tokens(user_id)

Deletes all of a user's refresh tokens. Answers 202.

iex> Auth0Client.Management.User.delete_refresh_tokens("auth0|23423")

delete_sessions(user_id)

Deletes all of a user's sessions, signing them out everywhere.

Auth0 accepts this asynchronously and answers 202.

iex> Auth0Client.Management.User.delete_sessions("auth0|23423")

effective_permission_source_roles(user_id, params \\ %{})

Lists the roles that grant a user a given permission, answering "why does this user have this permission?".

Pass resource_server_identifier and permission_name to name the permission.

iex> Auth0Client.Management.User.effective_permission_source_roles("auth0|23423", resource_server_identifier: "https://api.example.com", permission_name: "read:users")

effective_permissions(user_id, params \\ %{})

Lists every permission a user has, whether granted directly, through a role, or through a group.

Pass resource_server_identifier to limit it to one API. Uses checkpoint pagination — from and take.

iex> Auth0Client.Management.User.effective_permissions("auth0|23423")
iex> Auth0Client.Management.User.effective_permissions("auth0|23423", resource_server_identifier: "https://api.example.com")

effective_role_source_groups(user_id, params \\ %{})

Lists the groups that grant a user a given role, answering "why does this user have this role?".

Pass role_id to narrow it to one role.

iex> Auth0Client.Management.User.effective_role_source_groups("auth0|23423", role_id: "rol_abc123")

effective_roles(user_id, params \\ %{})

Lists every role a user has, whether assigned directly or inherited through a group.

roles/2 reports only direct assignments, so a user who gets their access through a group looks role-less to it. Use this when you need the truth.

Uses checkpoint pagination — from and take. Scopes: read:users read:roles

iex> Auth0Client.Management.User.effective_roles("auth0|23423")

enrollments(user_id)

Gets the user's first confirmed Guardian MFA enrollment.

Auth0 returns only the first confirmed enrollment here, not every enrollment the user has.

iex> Auth0Client.Management.User.enrollments("auth0|234")

get(user_id, params \\ %{})

Gets a specific user record with a given user id

iex> Auth0Client.Management.User.get("auth0|some_user_id")
iex> Auth0Client.Management.User.get("auth0|some_user_id", %{fields: "email,name,username"})

groups(user_id, params \\ %{})

Lists the groups a user belongs to

iex> Auth0Client.Management.User.groups("auth0|23423")

invalidate_remember_browser(user_id)

Invalidates every remembered browser, so the user is prompted for MFA again

iex> Auth0Client.Management.User.invalidate_remember_browser("auth0|23423")

link(id, body)

Links the account specified in the body to the given user_id param

iex> Auth0Client.Management.User.link("some_user_id", link_with: "secondary_acc_jwt")
iex> Auth0Client.Management.User.link("some_user_id", provider: "github", user_id: "23423", connection_id: "som")

log(user_id, params)

Get a user's log

iex> Auth0Client.Management.User.log("auth0|233423")
iex> Auth0Client.Management.User.log("auth0|23423", page: 2, per_page: 10)

organizations(user_id, params \\ %{})

Lists the organizations a user belongs to. Scopes: read:users read:organizations

iex> Auth0Client.Management.User.organizations("auth0|23423")

permissions(user_id, params \\ %{})

Lists the permissions granted to a user directly, ignoring any that come from a role. Use effective_permissions/2 for the full picture. Scopes: read:users

iex> Auth0Client.Management.User.permissions("auth0|23423")

refresh_tokens(user_id, params \\ %{})

Lists a user's refresh tokens. Uses checkpoint pagination.

iex> Auth0Client.Management.User.refresh_tokens("auth0|23423")

regenerate_recovery_code(id)

Removes current Guardain recovery code and generates new one

iex> Auth0Client.Management.User.regenerate_recovery_code("auth0|34234")

remove_permissions(user_id, permissions)

Removes permissions from a user. Scopes: update:users

iex> Auth0Client.Management.User.remove_permissions("auth0|23423", [{"https://api.example.com", "read:users"}])

remove_roles(user_id, role_ids)

Removes roles from a user. Scopes: update:users

iex> Auth0Client.Management.User.remove_roles("auth0|23423", ["rol_abc123"])

replace_authentication_methods(user_id, methods)

Replaces every authentication method the user has.

The body is a bare list, not an object wrapping one, and anything absent from it is removed.

iex> Auth0Client.Management.User.replace_authentication_methods("auth0|23423", [%{type: "email", email: "a@b.com"}])

revoke_access(user_id, body \\ %{})

Revokes a user's access — sessions and refresh tokens together. Answers 202.

session_id limits it to one session; preserve_refresh_tokens keeps the refresh tokens alive.

iex> Auth0Client.Management.User.revoke_access("auth0|23423")
iex> Auth0Client.Management.User.revoke_access("auth0|23423", %{preserve_refresh_tokens: true})

roles(user_id, params \\ %{})

List the roles associated with a user. Scopes: read:users read:roles

iex> Auth0Client.Management.User.roles("auth0|23423")

sessions(user_id, params \\ %{})

Lists a user's active sessions. Uses checkpoint pagination.

iex> Auth0Client.Management.User.sessions("auth0|23423")

unlink(primary_id, provider, secondary_id)

Unlinks an identity from the target user, and it becomes a separated user again.

iex> Auth0Client.Management.User.unlink("some_user_id", "github", "23984234")

update(user_id, body \\ %{})

Updates a user's information given a user id

iex> Auth0Client.Management.User.update("auth0|some_user_id", %{app_metadata: %{admin: false}})

update_authentication_method(user_id, method_id, body)

Updates an authentication method's name or preference

iex> Auth0Client.Management.User.update_authentication_method("auth0|23423", "aum_1", %{name: "Work phone"})