Back to Node Auth0

Class UsersClient

docs/classes/management.SDK.UsersClient-2.html

5.9.124.1 KB
Original Source

Class UsersClient

Index

Accessors

authenticationMethodsauthenticatorsconnectedAccountsenrollmentsfederatedConnectionsTokensetsgroupsidentitieslogsmultifactororganizationspermissionsriskAssessmentsrolesrefreshTokensessions

Constructors

constructor

Methods

listcreatelistUsersByEmailgetdeleteupdateregenerateRecoveryCoderevokeAccess

Properties

_options_authenticationMethods_authenticators_connectedAccounts_enrollments_federatedConnectionsTokensets_groups_identities_logs_multifactor_organizations_permissions_riskAssessments_roles_refreshToken_sessions

Accessors

authenticationMethods

get authenticationMethods(): AuthenticationMethodsClient

Returns AuthenticationMethodsClient

authenticators

get authenticators(): AuthenticatorsClient

Returns AuthenticatorsClient

connectedAccounts

get connectedAccounts(): ConnectedAccountsClient

Returns ConnectedAccountsClient

enrollments

get enrollments(): EnrollmentsClient

Returns EnrollmentsClient

federatedConnectionsTokensets

get federatedConnectionsTokensets(): FederatedConnectionsTokensetsClient

Returns FederatedConnectionsTokensetsClient

groups

get groups(): GroupsClient

Returns GroupsClient

identities

get identities(): IdentitiesClient

Returns IdentitiesClient

logs

get logs(): LogsClient

Returns LogsClient

multifactor

get multifactor(): MultifactorClient

Returns MultifactorClient

organizations

get organizations(): OrganizationsClient

Returns OrganizationsClient

permissions

get permissions(): PermissionsClient

Returns PermissionsClient

riskAssessments

get riskAssessments(): RiskAssessmentsClient

Returns RiskAssessmentsClient

roles

get roles(): RolesClient

Returns RolesClient

refreshToken

get refreshToken(): RefreshTokenClient

Returns RefreshTokenClient

sessions

get sessions(): SessionsClient

Returns SessionsClient

Constructors

constructor

new UsersClient(options: BaseClientOptions): UsersClient

Parameters

Returns UsersClient

Methods

list

list(
request?: ListUsersRequestParameters,
requestOptions?: UsersClient.RequestOptions,
): Promise<
Page<UserResponseSchema, ListUsersOffsetPaginatedResponseContent>,
>

Retrieve details of users. It is possible to:

  • Specify a search criteria for users
  • Sort the users to be returned
  • Select the fields to be returned
  • Specify the number of users to retrieve per page and the page index

The q query parameter can be used to get users that match the specified criteria using query string syntax.

Learn more about searching for users.

Read about best practices when working with the API endpoints for retrieving users.

Auth0 limits the number of users you can return. If you exceed this threshold, please redefine your search, use the export job, or the User Import / Export extension.

Parameters

Request-specific configuration.

Returns Promise<Page<UserResponseSchema, ListUsersOffsetPaginatedResponseContent>>

Throws

Management.BadRequestError

Throws

Management.UnauthorizedError

Throws

Management.ForbiddenError

Throws

Management.TooManyRequestsError

Throws

Management.ServiceUnavailableError

Example

await client.users.list({ page: 1, per_page: 1, include_totals: true, sort: "sort", connection: "connection", fields: "fields", include_fields: true, q: "q", search_engine: "v1", primary_order: true })Copy

create

create(
request: CreateUserRequestContent,
requestOptions?: UsersClient.RequestOptions,
): HttpResponsePromise<CreateUserResponseContent>

Create a new user for a given database or passwordless connection.

Note: connection is required but other parameters such as email and password are dependent upon the type of connection.

Parameters

Request-specific configuration.

Returns HttpResponsePromise<CreateUserResponseContent>

Throws

Management.BadRequestError

Throws

Management.UnauthorizedError

Throws

Management.ForbiddenError

Throws

Management.ConflictError

Throws

Management.TooManyRequestsError

Example

await client.users.create({ connection: "connection" })Copy

listUsersByEmail

listUsersByEmail(
request: ListUsersByEmailRequestParameters,
requestOptions?: UsersClient.RequestOptions,
): HttpResponsePromise<UserResponseSchema[]>

Find users by email. If Auth0 is the identity provider (idP), the email address associated with a user is saved in lower case, regardless of how you initially provided it.

For example, if you register a user as [email protected], Auth0 saves the user's email as [email protected].

Therefore, when using this endpoint, make sure that you are searching for users via email addresses using the correct case.

Parameters

Request-specific configuration.

Returns HttpResponsePromise<UserResponseSchema[]>

Throws

Management.BadRequestError

Throws

Management.UnauthorizedError

Throws

Management.ForbiddenError

Throws

Management.TooManyRequestsError

Example

await client.users.listUsersByEmail({ fields: "fields", include_fields: true, email: "email" })Copy

get

get(
id: string,
request?: GetUserRequestParameters,
requestOptions?: UsersClient.RequestOptions,
): HttpResponsePromise<GetUserResponseContent>

Retrieve user details. A list of fields to include or exclude may also be specified. For more information, see Retrieve Users with the Get Users Endpoint.

Parameters

  • id: string

ID of the user to retrieve.

Request-specific configuration.

Returns HttpResponsePromise<GetUserResponseContent>

Throws

Management.BadRequestError

Throws

Management.UnauthorizedError

Throws

Management.ForbiddenError

Throws

Management.NotFoundError

Throws

Management.TooManyRequestsError

Example

await client.users.get("id", { fields: "fields", include_fields: true })Copy

delete

delete(
id: string,
requestOptions?: UsersClient.RequestOptions,
): HttpResponsePromise<void>

Delete a user by user ID. This action cannot be undone. For Auth0 Dashboard instructions, see Delete Users.

Parameters

  • id: string

ID of the user to delete.

Request-specific configuration.

Returns HttpResponsePromise<void>

Throws

Management.BadRequestError

Throws

Management.UnauthorizedError

Throws

Management.ForbiddenError

Throws

Management.TooManyRequestsError

Example

await client.users.delete("id")Copy

update

update(
id: string,
request?: UpdateUserRequestContent,
requestOptions?: UsersClient.RequestOptions,
): HttpResponsePromise<UpdateUserResponseContent>

Update a user.

These are the attributes that can be updated at the root level:

  • app_metadata
  • blocked
  • email
  • email_verified
  • family_name
  • given_name
  • name
  • nickname
  • password
  • phone_number
  • phone_verified
  • picture
  • username
  • user_metadata
  • verify_email

Some considerations:

  • The properties of the new object will replace the old ones.
  • The metadata fields are an exception to this rule (user_metadata and app_metadata). These properties are merged instead of being replaced but be careful, the merge only occurs on the first level.
  • If you are updating email, email_verified, phone_number, phone_verified, username or password of a secondary identity, you need to specify the connection property too.
  • If you are updating email or phone_number you can specify, optionally, the client_id property.
  • Updating email_verified is not supported for enterprise and passwordless sms connections.
  • Updating the blocked to false does not affect the user's blocked state from an excessive amount of incorrectly provided credentials. Use the "Unblock a user" endpoint from the "User Blocks" API to change the user's state.
  • Supported attributes can be unset by supplying null as the value.
Updating a field (non-metadata property)

To mark the email address of a user as verified, the body to send should be:

{ "email_verified": true }
Updating a user metadata root property

Let's assume that our test user has the following user_metadata:

{ "user_metadata" : { "profileCode": 1479 } }

To add the field addresses the body to send should be:

{ "user_metadata" : { "addresses": {"work_address": "100 Industrial Way"} }}

The modified object ends up with the following user_metadata property:

{
"user_metadata": {
"profileCode": 1479,
"addresses": { "work_address": "100 Industrial Way" }
}
}
Updating an inner user metadata property

If there's existing user metadata to which we want to add "home_address": "742 Evergreen Terrace" (using the addresses property) we should send the whole addresses object. Since this is a first-level object, the object will be merged in, but its own properties will not be. The body to send should be:

{
  "user_metadata": {
    "addresses": {
      "work_address": "100 Industrial Way",
      "home_address": "742 Evergreen Terrace"
    }
  }
}

The modified object ends up with the following user_metadata property:

{
  "user_metadata": {
    "profileCode": 1479,
    "addresses": {
      "work_address": "100 Industrial Way",
      "home_address": "742 Evergreen Terrace"
    }
  }
}

Parameters

  • id: string

ID of the user to update.

Request-specific configuration.

Returns HttpResponsePromise<UpdateUserResponseContent>

Throws

Management.BadRequestError

Throws

Management.UnauthorizedError

Throws

Management.ForbiddenError

Throws

Management.NotFoundError

Throws

Management.TooManyRequestsError

Example

await client.users.update("id")Copy

regenerateRecoveryCode

regenerateRecoveryCode(
id: string,
requestOptions?: UsersClient.RequestOptions,
): HttpResponsePromise<RegenerateUsersRecoveryCodeResponseContent>

Remove an existing multi-factor authentication (MFA) recovery code and generate a new one. If a user cannot access the original device or account used for MFA enrollment, they can use a recovery code to authenticate.

Parameters

  • id: string

ID of the user to regenerate a multi-factor authentication recovery code for.

Request-specific configuration.

Returns HttpResponsePromise<RegenerateUsersRecoveryCodeResponseContent>

Throws

Management.BadRequestError

Throws

Management.UnauthorizedError

Throws

Management.ForbiddenError

Throws

Management.NotFoundError

Example

await client.users.regenerateRecoveryCode("id")Copy

revokeAccess

revokeAccess(
id: string,
request?: RevokeUserAccessRequestContent,
requestOptions?: UsersClient.RequestOptions,
): HttpResponsePromise<void>

Revokes selected resources related to a user (sessions, refresh tokens, ...).

Parameters

  • id: string

ID of the user.

Request-specific configuration.

Returns HttpResponsePromise<void>

Throws

Management.BadRequestError

Throws

Management.UnauthorizedError

Throws

Management.ForbiddenError

Throws

Management.TooManyRequestsError

Example

await client.users.revokeAccess("id")Copy

Properties

Protected Readonly_options

_options: NormalizedClientOptionsWithAuth<BaseClientOptions>

Protected_authenticationMethods

_authenticationMethods: AuthenticationMethodsClient | undefined

Protected_authenticators

_authenticators: AuthenticatorsClient | undefined

Protected_connectedAccounts

_connectedAccounts: ConnectedAccountsClient | undefined

Protected_enrollments

_enrollments: EnrollmentsClient | undefined

Protected_federatedConnectionsTokensets

_federatedConnectionsTokensets: FederatedConnectionsTokensetsClient | undefined

Protected_groups

_groups: GroupsClient | undefined

Protected_identities

_identities: IdentitiesClient | undefined

Protected_logs

_logs: LogsClient | undefined

Protected_multifactor

_multifactor: MultifactorClient | undefined

Protected_organizations

_organizations: OrganizationsClient | undefined

Protected_permissions

_permissions: PermissionsClient | undefined

Protected_riskAssessments

_riskAssessments: RiskAssessmentsClient | undefined

Protected_roles

_roles: RolesClient | undefined

Protected_refreshToken

_refreshToken: RefreshTokenClient | undefined

Protected_sessions

_sessions: SessionsClient | undefined

Settings

Member Visibility

  • Protected
  • Inherited

ThemeOSLightDark

On This Page

Accessors authenticationMethodsauthenticatorsconnectedAccountsenrollmentsfederatedConnectionsTokensetsgroupsidentitieslogsmultifactororganizationspermissionsriskAssessmentsrolesrefreshTokensessions Constructors constructor Methods listcreatelistUsersByEmailgetdeleteupdateregenerateRecoveryCoderevokeAccess Properties _options_authenticationMethods_authenticators_connectedAccounts_enrollments_federatedConnectionsTokensets_groups_identities_logs_multifactor_organizations_permissions_riskAssessments_roles_refreshToken_sessions