Class: Auth0::Users::Client
- Inherits:
-
Object
- Object
- Auth0::Users::Client
- Defined in:
- lib/auth0/users/client.rb
Instance Method Summary collapse
- #authentication_methods ⇒ Auth0::AuthenticationMethods::Client
- #authenticators ⇒ Auth0::Authenticators::Client
- #connected_accounts ⇒ Auth0::ConnectedAccounts::Client
-
#create(request_options: {}, **params) ⇒ Auth0::Types::CreateUserResponseContent
Create a new user for a given <a href=“auth0.com/docs/connections/database”>database</a> or <a href=“auth0.com/docs/connections/passwordless”>passwordless</a> connection.
-
#delete(request_options: {}, **params) ⇒ untyped
Delete a user by user ID.
- #enrollments ⇒ Auth0::Enrollments::Client
- #federated_connections_tokensets ⇒ Auth0::FederatedConnectionsTokensets::Client
-
#get(request_options: {}, **params) ⇒ Auth0::Types::GetUserResponseContent
Retrieve user details.
- #groups ⇒ Auth0::Groups::Client
- #identities ⇒ Auth0::Identities::Client
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Auth0::Types::ListUsersOffsetPaginatedResponseContent
Retrieve details of users.
-
#list_users_by_email(request_options: {}, **params) ⇒ Array[Auth0::Types::UserResponseSchema]
Find users by email.
- #logs ⇒ Auth0::Logs::Client
- #multifactor ⇒ Auth0::Multifactor::Client
- #organizations ⇒ Auth0::Organizations::Client
- #permissions ⇒ Auth0::Permissions::Client
- #refresh_token ⇒ Auth0::RefreshToken::Client
-
#regenerate_recovery_code(request_options: {}, **params) ⇒ Auth0::Types::RegenerateUsersRecoveryCodeResponseContent
Remove an existing multi-factor authentication (MFA) <a href=“auth0.com/docs/secure/multi-factor-authentication/reset-user-mfa”>recovery code</a> and generate a new one.
-
#revoke_access(request_options: {}, **params) ⇒ untyped
Revokes selected resources related to a user (sessions, refresh tokens, …).
- #risk_assessments ⇒ Auth0::RiskAssessments::Client
- #roles ⇒ Auth0::Roles::Client
- #sessions ⇒ Auth0::Sessions::Client
-
#update(request_options: {}, **params) ⇒ Auth0::Types::UpdateUserResponseContent
Update a user.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/auth0/users/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#authentication_methods ⇒ Auth0::AuthenticationMethods::Client
455 456 457 |
# File 'lib/auth0/users/client.rb', line 455 def authentication_methods @authentication_methods ||= Auth0::Users::AuthenticationMethods::Client.new(client: @client) end |
#authenticators ⇒ Auth0::Authenticators::Client
460 461 462 |
# File 'lib/auth0/users/client.rb', line 460 def authenticators @authenticators ||= Auth0::Users::Authenticators::Client.new(client: @client) end |
#connected_accounts ⇒ Auth0::ConnectedAccounts::Client
465 466 467 |
# File 'lib/auth0/users/client.rb', line 465 def connected_accounts @connected_accounts ||= Auth0::Users::ConnectedAccounts::Client.new(client: @client) end |
#create(request_options: {}, **params) ⇒ Auth0::Types::CreateUserResponseContent
Create a new user for a given <a href=“auth0.com/docs/connections/database”>database</a> or <a href=“auth0.com/docs/connections/passwordless”>passwordless</a> connection.
Note: connection is required but other parameters such as email and password are dependent upon the type of connection.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/auth0/users/client.rb', line 111 def create(request_options: {}, **params) params = Auth0::Internal::Types::Utils.normalize_keys(params) request = Auth0::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "users", body: Auth0::Users::Types::CreateUserRequestContent.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Auth0::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Auth0::Types::CreateUserResponseContent.load(response.body) else error_class = Auth0::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ untyped
Delete a user by user ID. This action cannot be undone. For Auth0 Dashboard instructions, see <a href=“auth0.com/docs/manage-users/user-accounts/delete-users”>Delete Users</a>.
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/auth0/users/client.rb', line 241 def delete(request_options: {}, **params) params = Auth0::Internal::Types::Utils.normalize_keys(params) request = Auth0::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "users/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Auth0::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Auth0::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#enrollments ⇒ Auth0::Enrollments::Client
470 471 472 |
# File 'lib/auth0/users/client.rb', line 470 def enrollments @enrollments ||= Auth0::Users::Enrollments::Client.new(client: @client) end |
#federated_connections_tokensets ⇒ Auth0::FederatedConnectionsTokensets::Client
475 476 477 |
# File 'lib/auth0/users/client.rb', line 475 def federated_connections_tokensets @federated_connections_tokensets ||= Auth0::Users::FederatedConnectionsTokensets::Client.new(client: @client) end |
#get(request_options: {}, **params) ⇒ Auth0::Types::GetUserResponseContent
Retrieve user details. A list of fields to include or exclude may also be specified. For more information, see <a href=“auth0.com/docs/manage-users/user-search/retrieve-users-with-get-users-endpoint”>Retrieve Users with the Get Users Endpoint</a>.
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/auth0/users/client.rb', line 199 def get(request_options: {}, **params) params = Auth0::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[fields include_fields] query_params = {} query_params["fields"] = params[:fields] if params.key?(:fields) query_params["include_fields"] = params[:include_fields] if params.key?(:include_fields) params = params.except(*query_param_names) request = Auth0::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "users/#{URI.encode_uri_component(params[:id].to_s)}", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Auth0::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Auth0::Types::GetUserResponseContent.load(response.body) else error_class = Auth0::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#groups ⇒ Auth0::Groups::Client
480 481 482 |
# File 'lib/auth0/users/client.rb', line 480 def groups @groups ||= Auth0::Users::Groups::Client.new(client: @client) end |
#identities ⇒ Auth0::Identities::Client
485 486 487 |
# File 'lib/auth0/users/client.rb', line 485 def identities @identities ||= Auth0::Users::Identities::Client.new(client: @client) end |
#list(request_options: {}, **params) ⇒ Auth0::Types::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
<!-- only v3 is available -->
The q query parameter can be used to get users that match the specified criteria <a href=“auth0.com/docs/users/search/v3/query-syntax”>using query string syntax.</a>
<a href=“auth0.com/docs/users/search/v3”>Learn more about searching for users.</a>
Read about <a href=“auth0.com/docs/users/search/best-practices”>best practices</a> 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 <a href=“auth0.com/docs/api/management/v2#!/Jobs/post_users_exports”>export job</a>, or the <a href=“auth0.com/docs/extensions/user-import-export”>User Import / Export</a> extension.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/auth0/users/client.rb', line 51 def list(request_options: {}, **params) params = Auth0::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[page per_page include_totals sort connection fields include_fields q search_engine primary_order] query_params = {} query_params["page"] = params.fetch(:page, 0) query_params["per_page"] = params.fetch(:per_page, 50) query_params["include_totals"] = params.fetch(:include_totals, true) query_params["sort"] = params[:sort] if params.key?(:sort) query_params["connection"] = params[:connection] if params.key?(:connection) query_params["fields"] = params[:fields] if params.key?(:fields) query_params["include_fields"] = params[:include_fields] if params.key?(:include_fields) query_params["q"] = params[:q] if params.key?(:q) query_params["search_engine"] = params[:search_engine] if params.key?(:search_engine) query_params["primary_order"] = params[:primary_order] if params.key?(:primary_order) params.except(*query_param_names) Auth0::Internal::OffsetItemIterator.new( initial_page: query_params["page"], item_field: :users, has_next_field: nil, step: true ) do |next_page| query_params["page"] = next_page request = Auth0::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "users", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Auth0::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Auth0::Types::ListUsersOffsetPaginatedResponseContent.load(response.body) else error_class = Auth0::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end end |
#list_users_by_email(request_options: {}, **params) ⇒ Array[Auth0::Types::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 JohnSmith@example.com, Auth0 saves the user’s email as johnsmith@example.com.
Therefore, when using this endpoint, make sure that you are searching for users via email addresses using the correct case.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/auth0/users/client.rb', line 155 def list_users_by_email(request_options: {}, **params) params = Auth0::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[fields include_fields email] query_params = {} query_params["fields"] = params[:fields] if params.key?(:fields) query_params["include_fields"] = params[:include_fields] if params.key?(:include_fields) query_params["email"] = params[:email] if params.key?(:email) params.except(*query_param_names) request = Auth0::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "users-by-email", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Auth0::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Auth0::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#logs ⇒ Auth0::Logs::Client
490 491 492 |
# File 'lib/auth0/users/client.rb', line 490 def logs @logs ||= Auth0::Users::Logs::Client.new(client: @client) end |
#multifactor ⇒ Auth0::Multifactor::Client
495 496 497 |
# File 'lib/auth0/users/client.rb', line 495 def multifactor @multifactor ||= Auth0::Users::Multifactor::Client.new(client: @client) end |
#organizations ⇒ Auth0::Organizations::Client
500 501 502 |
# File 'lib/auth0/users/client.rb', line 500 def organizations @organizations ||= Auth0::Users::Organizations::Client.new(client: @client) end |
#permissions ⇒ Auth0::Permissions::Client
505 506 507 |
# File 'lib/auth0/users/client.rb', line 505 def @permissions ||= Auth0::Users::Permissions::Client.new(client: @client) end |
#refresh_token ⇒ Auth0::RefreshToken::Client
520 521 522 |
# File 'lib/auth0/users/client.rb', line 520 def refresh_token @refresh_token ||= Auth0::Users::RefreshToken::Client.new(client: @client) end |
#regenerate_recovery_code(request_options: {}, **params) ⇒ Auth0::Types::RegenerateUsersRecoveryCodeResponseContent
Remove an existing multi-factor authentication (MFA) <a href=“auth0.com/docs/secure/multi-factor-authentication/reset-user-mfa”>recovery code</a> 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.
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/auth0/users/client.rb', line 395 def regenerate_recovery_code(request_options: {}, **params) params = Auth0::Internal::Types::Utils.normalize_keys(params) request = Auth0::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "users/#{URI.encode_uri_component(params[:id].to_s)}/recovery-code-regeneration", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Auth0::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Auth0::Types::RegenerateUsersRecoveryCodeResponseContent.load(response.body) else error_class = Auth0::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#revoke_access(request_options: {}, **params) ⇒ untyped
Revokes selected resources related to a user (sessions, refresh tokens, …).
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 |
# File 'lib/auth0/users/client.rb', line 429 def revoke_access(request_options: {}, **params) params = Auth0::Internal::Types::Utils.normalize_keys(params) request_data = Auth0::Users::Types::RevokeUserAccessRequestContent.new(params).to_h non_body_param_names = ["id"] body = request_data.except(*non_body_param_names) request = Auth0::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "users/#{URI.encode_uri_component(params[:id].to_s)}/revoke-access", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Auth0::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Auth0::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#risk_assessments ⇒ Auth0::RiskAssessments::Client
510 511 512 |
# File 'lib/auth0/users/client.rb', line 510 def risk_assessments @risk_assessments ||= Auth0::Users::RiskAssessments::Client.new(client: @client) end |
#roles ⇒ Auth0::Roles::Client
515 516 517 |
# File 'lib/auth0/users/client.rb', line 515 def roles @roles ||= Auth0::Users::Roles::Client.new(client: @client) end |
#sessions ⇒ Auth0::Sessions::Client
525 526 527 |
# File 'lib/auth0/users/client.rb', line 525 def sessions @sessions ||= Auth0::Users::Sessions::Client.new(client: @client) end |
#update(request_options: {}, **params) ⇒ Auth0::Types::UpdateUserResponseContent
Update a user.
These are the attributes that can be updated at the root level:
<ul>
<li>app_metadata</li>
<li>blocked</li>
<li>email</li>
<li>email_verified</li>
<li>family_name</li>
<li>given_name</li>
<li>name</li>
<li>nickname</li>
<li>password</li>
<li>phone_number</li>
<li>phone_verified</li>
<li>picture</li>
<li>username</li>
<li>user_metadata</li>
<li>verify_email</li>
</ul>
Some considerations: <ul>
<li>The properties of the new object will replace the old ones.</li>
<li>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.</li> <li>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.</li> <li>If you are updating email or phone_number you can specify, optionally, the client_id property.</li> <li>Updating email_verified is not supported for enterprise and passwordless sms connections.</li> <li>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.</li>
<li>Supported attributes can be unset by supplying <code>null</code> as the value.</li>
</ul>
<h5>Updating a field (non-metadata property)</h5> To mark the email address of a user as verified, the body to send should be: <pre>{ "email_verified": true }</pre>
<h5>Updating a user metadata root property</h5>Let’s assume that our test user has the following user_metadata: <pre>{ "user_metadata" : { "profileCode": 1479 } }</pre>
To add the field addresses the body to send should be: <pre>{ "user_metadata" : { "addresses": {"work_address": "100 Industrial Way"} }}</pre>
The modified object ends up with the following user_metadata property:<pre><code>{
"user_metadata": {
"profileCode": 1479,
"addresses": { "work_address": "100 Industrial Way" }
}
}</code></pre>
<h5>Updating an inner user metadata property</h5>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: <pre><code>{
"user_metadata": {
"addresses": {
"work_address": "100 Industrial Way",
"home_address": "742 Evergreen Terrace"
}
}
}</code></pre>
The modified object ends up with the following user_metadata property: <pre><code>{
"user_metadata": {
"profileCode": 1479,
"addresses": {
"work_address": "100 Industrial Way",
"home_address": "742 Evergreen Terrace"
}
}
}</code></pre>
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/auth0/users/client.rb', line 353 def update(request_options: {}, **params) params = Auth0::Internal::Types::Utils.normalize_keys(params) request_data = Auth0::Users::Types::UpdateUserRequestContent.new(params).to_h non_body_param_names = ["id"] body = request_data.except(*non_body_param_names) request = Auth0::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "users/#{URI.encode_uri_component(params[:id].to_s)}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Auth0::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Auth0::Types::UpdateUserResponseContent.load(response.body) else error_class = Auth0::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |