Module: Auth0::Api::V2::Users
Overview
Methods to use the users endpoints
Instance Method Summary collapse
-
#add_user_permissions(user_id, permissions) ⇒ Object
Add one or more permissions from a specific user.
-
#add_user_roles(user_id, roles) ⇒ Object
Add one or more roles to a specific user.
-
#create_user(name, options = {}) ⇒ json
Creates a new user according to optional parameters received.
-
#delete_user(user_id) ⇒ Object
Deletes a single user given its id.
-
#delete_user_provider(user_id, provider_name) ⇒ Object
Delete a user’s multifactor provider.
-
#delete_users ⇒ Object
deprecated
Deprecated.
-
4.8.0, endpoint has been removed
-
-
#generate_recovery_code(user_id) ⇒ Object
Remove the current Guardian recovery code and generates and returns a new one.
-
#get_enrollments(user_id) ⇒ json
Get all Guardian enrollments for a specific user.
-
#get_user_permissions(user_id) ⇒ json
Get all permissions for a specific user.
-
#get_user_roles(user_id, options = {}) ⇒ json
Get all roles assigned to a specific user.
-
#invalidate_browsers(user_id) ⇒ Object
Invalidate all remembered browsers for all authentication factors for a specific user.
-
#link_user_account(user_id, body) ⇒ json
Links the account specified in the body (secondary account) to the account specified by the id param of the URL (primary account).
-
#patch_user(user_id, body) ⇒ json
(also: #update_user)
Updates a user with the object’s properties received in the optional parameters.
-
#remove_user_permissions(user_id, permissions) ⇒ Object
Remove one or more permissions from a specific user.
-
#remove_user_roles(user_id, roles) ⇒ Object
Remove one or more roles from a specific user.
-
#unlink_user_account(user_id, provider, secondary_user_id) ⇒ json
(also: #unlink_users_account)
Unlink a user account.
-
#user(user_id, fields: nil, include_fields: true) ⇒ json
Retrieves a user given a user_id.
-
#user_logs(user_id, options = {}) ⇒ json
(also: #get_user_log_events)
Retrieve every log event for a specific user id rubocop:disable Metrics/MethodLength, Metrics/AbcSize.
-
#users(options = {}) ⇒ json
(also: #get_users)
Retrieves a list of Auth0 users.
Methods included from Mixins::Validation
#validate_permissions_array, #validate_strings_array
Instance Method Details
#add_user_permissions(user_id, permissions) ⇒ Object
Add one or more permissions from a specific user.
274 275 276 277 278 |
# File 'lib/auth0/api/v2/users.rb', line 274 def (user_id, ) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? = post "#{users_path}/#{user_id}/permissions", permissions: end |
#add_user_roles(user_id, roles) ⇒ Object
Add one or more roles to a specific user.
229 230 231 232 233 234 |
# File 'lib/auth0/api/v2/users.rb', line 229 def add_user_roles(user_id, roles) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? validate_strings_array roles path = "#{users_path}/#{user_id}/roles" post(path, roles: roles) end |
#create_user(name, options = {}) ⇒ json
Creates a new user according to optional parameters received. The attribute connection is always mandatory but depending on the type of connection you are using there could be others too. For instance, Auth0 DB Connections require email and password.
50 51 52 53 54 |
# File 'lib/auth0/api/v2/users.rb', line 50 def create_user(name, = {}) request_params = Hash[.map { |(k, v)| [k.to_sym, v] }] request_params[:name] = name post(users_path, request_params) end |
#delete_user(user_id) ⇒ Object
Deletes a single user given its id
82 83 84 85 86 |
# File 'lib/auth0/api/v2/users.rb', line 82 def delete_user(user_id) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? path = "#{users_path}/#{user_id}" delete(path) end |
#delete_user_provider(user_id, provider_name) ⇒ Object
Delete a user’s multifactor provider
116 117 118 119 120 121 |
# File 'lib/auth0/api/v2/users.rb', line 116 def delete_user_provider(user_id, provider_name) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? raise Auth0::InvalidParameter, 'Must supply a valid provider name' if provider_name.to_s.empty? path = "#{users_path}/#{user_id}/multifactor/#{provider_name}" delete(path) end |
#delete_users ⇒ Object
-
4.8.0, endpoint has been removed
Delete all users - USE WITH CAUTION
58 59 60 |
# File 'lib/auth0/api/v2/users.rb', line 58 def delete_users delete(users_path) end |
#generate_recovery_code(user_id) ⇒ Object
Remove the current Guardian recovery code and generates and returns a new one.
284 285 286 287 |
# File 'lib/auth0/api/v2/users.rb', line 284 def generate_recovery_code(user_id) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? post "#{users_path}/#{user_id}/recovery-code-generation" end |
#get_enrollments(user_id) ⇒ json
Get all Guardian enrollments for a specific user
242 243 244 245 |
# File 'lib/auth0/api/v2/users.rb', line 242 def get_enrollments(user_id) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? get "#{users_path}/#{user_id}/enrollments" end |
#get_user_permissions(user_id) ⇒ json
Get all permissions for a specific user.
253 254 255 256 |
# File 'lib/auth0/api/v2/users.rb', line 253 def (user_id) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? get "#{users_path}/#{user_id}/permissions" end |
#get_user_roles(user_id, options = {}) ⇒ json
Get all roles assigned to a specific user.
201 202 203 204 205 206 207 208 209 210 |
# File 'lib/auth0/api/v2/users.rb', line 201 def get_user_roles(user_id, = {}) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? path = "#{users_path}/#{user_id}/roles" request_params = { per_page: .fetch(:per_page, nil), page: .fetch(:page, nil), include_totals: .fetch(:include_totals, nil) } get(path, request_params) end |
#invalidate_browsers(user_id) ⇒ Object
Invalidate all remembered browsers for all authentication factors for a specific user.
293 294 295 296 |
# File 'lib/auth0/api/v2/users.rb', line 293 def invalidate_browsers(user_id) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? post "#{users_path}/#{user_id}/multifactor/actions/invalidate-remember-browser" end |
#link_user_account(user_id, body) ⇒ json
Links the account specified in the body (secondary account) to the account specified by the id param of the URL (primary account).
-
With the authenticated primary account’s JWT in the Authorization header, which has the
update:current_user_identities scope. In this case only the link_with param is required in the body, containing the JWT obtained upon the secondary account’s authentication.
-
With an API V2 generated token with update:users scope. In this case you need to send provider and user_id
in the body. Optionally you can also send the connection_id param which is suitable for identifying a particular database connection for the ‘auth0’ provider.
136 137 138 139 140 141 |
# File 'lib/auth0/api/v2/users.rb', line 136 def link_user_account(user_id, body) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? raise Auth0::InvalidParameter, 'Must supply a valid body' if body.to_s.empty? path = "#{users_path}/#{user_id}/identities" post(path, body) end |
#patch_user(user_id, body) ⇒ json Also known as: update_user
Updates a user with the object’s properties received in the optional parameters. These are the attributes that can be updated at the root level: blocked, email_verified, email, verify_email, password, phone_number, phone_verified, verify_password, user_metadata, app_metadata, username 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_verified, phone_verified, username or password you need to specify the connection property too. If your are updating email or phone_number you need to specify the connection and the client_id properties.
104 105 106 107 108 109 |
# File 'lib/auth0/api/v2/users.rb', line 104 def patch_user(user_id, body) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? raise Auth0::InvalidParameter, 'Must supply a valid body' if body.to_s.empty? || body.empty? path = "#{users_path}/#{user_id}" patch(path, body) end |
#remove_user_permissions(user_id, permissions) ⇒ Object
Remove one or more permissions from a specific user.
263 264 265 266 267 |
# File 'lib/auth0/api/v2/users.rb', line 263 def (user_id, ) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? = delete_with_body "#{users_path}/#{user_id}/permissions", permissions: end |
#remove_user_roles(user_id, roles) ⇒ Object
Remove one or more roles from a specific user.
217 218 219 220 221 222 |
# File 'lib/auth0/api/v2/users.rb', line 217 def remove_user_roles(user_id, roles) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? validate_strings_array roles path = "#{users_path}/#{user_id}/roles" delete_with_body path, roles: roles end |
#unlink_user_account(user_id, provider, secondary_user_id) ⇒ json Also known as: unlink_users_account
Unlink a user account
150 151 152 153 154 155 156 |
# File 'lib/auth0/api/v2/users.rb', line 150 def unlink_user_account(user_id, provider, secondary_user_id) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? raise Auth0::MissingUserId, 'Must supply a valid secondary user_id' if secondary_user_id.to_s.empty? raise Auth0::InvalidParameter, 'Must supply a valid provider' if provider.to_s.empty? path = "#{users_path}/#{user_id}/identities/#{provider}/#{secondary_user_id}" delete(path) end |
#user(user_id, fields: nil, include_fields: true) ⇒ json
Retrieves a user given a user_id
69 70 71 72 73 74 75 76 77 |
# File 'lib/auth0/api/v2/users.rb', line 69 def user(user_id, fields: nil, include_fields: true) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? path = "#{users_path}/#{user_id}" request_params = { fields: fields, include_fields: include_fields } get(path, request_params) end |
#user_logs(user_id, options = {}) ⇒ json Also known as: get_user_log_events
Retrieve every log event for a specific user id rubocop:disable Metrics/MethodLength, Metrics/AbcSize
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/auth0/api/v2/users.rb', line 170 def user_logs(user_id, = {}) raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty? path = "#{users_path}/#{user_id}/logs" request_params = { per_page: .fetch(:per_page, nil), page: .fetch(:page, nil), include_totals: .fetch(:include_totals, nil), sort: .fetch(:sort, nil) } if request_params[:per_page].to_i > 100 raise Auth0::InvalidParameter, 'The total amount of entries per page should be less than 100' end sort_pattern = /^(([a-zA-Z0-9_\.]+))\:(1|-1)$/ if !request_params[:sort].nil? && !sort_pattern.match(request_params[:sort]) raise Auth0::InvalidParameter, 'Sort does not match pattern ^(([a-zA-Z0-9_\\.]+))\\:(1|-1)$' end get(path, request_params) end |
#users(options = {}) ⇒ json Also known as: get_users
Retrieves a list of Auth0 users.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/auth0/api/v2/users.rb', line 26 def users( = {}) request_params = { per_page: .fetch(:per_page, nil), page: .fetch(:page, nil), include_totals: .fetch(:include_totals, nil), sort: .fetch(:sort, nil), connection: .fetch(:connection, nil), fields: .fetch(:fields, nil), include_fields: .fetch(:include_fields, nil), q: .fetch(:q, nil), search_engine: .fetch(:search_engine, nil) } get(users_path, request_params) end |