auth0 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +2 -1
- data/.rubocop_todo.yml +0 -2
- data/.travis.yml +4 -2
- data/CHANGELOG.md +40 -38
- data/DEPLOYMENT.md +5 -0
- data/Gemfile +1 -1
- data/README.md +20 -2
- data/Rakefile +1 -1
- data/auth0.gemspec +4 -3
- data/doc_config/templates/default/layout/html/footer.erb +1 -1
- data/examples/ruby-api/.gitignore +86 -0
- data/examples/ruby-api/Gemfile +8 -0
- data/examples/ruby-api/README.md +24 -0
- data/examples/ruby-api/config.ru +2 -0
- data/examples/ruby-api/main.rb +33 -0
- data/examples/ruby-on-rails-api/.gitignore +18 -0
- data/examples/ruby-on-rails-api/Gemfile +48 -0
- data/examples/ruby-on-rails-api/README.md +27 -0
- data/examples/ruby-on-rails-api/Rakefile +6 -0
- data/examples/ruby-on-rails-api/app/assets/images/.keep +0 -0
- data/examples/ruby-on-rails-api/app/assets/javascripts/application.js +16 -0
- data/examples/ruby-on-rails-api/app/assets/stylesheets/application.css +15 -0
- data/examples/ruby-on-rails-api/app/controllers/application_controller.rb +8 -0
- data/examples/ruby-on-rails-api/app/controllers/concerns/.keep +0 -0
- data/examples/ruby-on-rails-api/app/controllers/ping_controller.rb +6 -0
- data/examples/ruby-on-rails-api/app/controllers/secured_ping_controller.rb +11 -0
- data/examples/ruby-on-rails-api/app/helpers/application_helper.rb +3 -0
- data/examples/ruby-on-rails-api/app/mailers/.keep +0 -0
- data/examples/ruby-on-rails-api/app/models/.keep +0 -0
- data/examples/ruby-on-rails-api/app/models/concerns/.keep +0 -0
- data/examples/ruby-on-rails-api/app/views/layouts/application.html.erb +14 -0
- data/examples/ruby-on-rails-api/bin/bundle +3 -0
- data/examples/ruby-on-rails-api/bin/rails +4 -0
- data/examples/ruby-on-rails-api/bin/rake +4 -0
- data/examples/ruby-on-rails-api/bin/setup +29 -0
- data/examples/ruby-on-rails-api/config.ru +4 -0
- data/examples/ruby-on-rails-api/config/application.rb +23 -0
- data/examples/ruby-on-rails-api/config/boot.rb +4 -0
- data/examples/ruby-on-rails-api/config/database.yml +27 -0
- data/examples/ruby-on-rails-api/config/environment.rb +5 -0
- data/examples/ruby-on-rails-api/config/environments/development.rb +37 -0
- data/examples/ruby-on-rails-api/config/environments/production.rb +83 -0
- data/examples/ruby-on-rails-api/config/environments/test.rb +41 -0
- data/examples/ruby-on-rails-api/config/initializers/backtrace_silencers.rb +7 -0
- data/examples/ruby-on-rails-api/config/initializers/cookies_serializer.rb +3 -0
- data/examples/ruby-on-rails-api/config/initializers/dotenv.rb +4 -0
- data/examples/ruby-on-rails-api/config/initializers/filter_parameter_logging.rb +4 -0
- data/examples/ruby-on-rails-api/config/initializers/inflections.rb +16 -0
- data/examples/ruby-on-rails-api/config/initializers/knock.rb +53 -0
- data/examples/ruby-on-rails-api/config/initializers/mime_types.rb +4 -0
- data/examples/ruby-on-rails-api/config/initializers/session_store.rb +3 -0
- data/examples/ruby-on-rails-api/config/initializers/wrap_parameters.rb +14 -0
- data/examples/ruby-on-rails-api/config/locales/en.yml +23 -0
- data/examples/ruby-on-rails-api/config/routes.rb +58 -0
- data/examples/ruby-on-rails-api/config/secrets.yml +28 -0
- data/examples/ruby-on-rails-api/db/schema.rb +15 -0
- data/examples/ruby-on-rails-api/db/seeds.rb +7 -0
- data/examples/ruby-on-rails-api/lib/assets/.keep +0 -0
- data/examples/ruby-on-rails-api/lib/tasks/.keep +0 -0
- data/examples/ruby-on-rails-api/log/.keep +0 -0
- data/examples/ruby-on-rails-api/public/404.html +67 -0
- data/examples/ruby-on-rails-api/public/422.html +67 -0
- data/examples/ruby-on-rails-api/public/500.html +66 -0
- data/examples/ruby-on-rails-api/public/favicon.ico +0 -0
- data/examples/ruby-on-rails-api/public/robots.txt +5 -0
- data/examples/ruby-on-rails-api/test/controllers/.keep +0 -0
- data/examples/ruby-on-rails-api/test/fixtures/.keep +0 -0
- data/examples/ruby-on-rails-api/test/helpers/.keep +0 -0
- data/examples/ruby-on-rails-api/test/integration/.keep +0 -0
- data/examples/ruby-on-rails-api/test/mailers/.keep +0 -0
- data/examples/ruby-on-rails-api/test/models/.keep +0 -0
- data/examples/ruby-on-rails-api/test/ping_controller_test.rb +8 -0
- data/examples/ruby-on-rails-api/test/secured_ping_controller_test.rb +26 -0
- data/examples/ruby-on-rails-api/test/test_helper.rb +16 -0
- data/lib/auth0/api/authentication_endpoints.rb +59 -30
- data/lib/auth0/api/v1/clients.rb +1 -1
- data/lib/auth0/api/v1/connections.rb +4 -3
- data/lib/auth0/api/v1/logs.rb +1 -1
- data/lib/auth0/api/v1/rules.rb +1 -1
- data/lib/auth0/api/v1/users.rb +5 -5
- data/lib/auth0/api/v2.rb +10 -0
- data/lib/auth0/api/v2/blacklists.rb +1 -1
- data/lib/auth0/api/v2/client_grants.rb +57 -0
- data/lib/auth0/api/v2/clients.rb +14 -14
- data/lib/auth0/api/v2/connections.rb +19 -20
- data/lib/auth0/api/v2/device_credentials.rb +76 -0
- data/lib/auth0/api/v2/emails.rb +5 -7
- data/lib/auth0/api/v2/jobs.rb +15 -12
- data/lib/auth0/api/v2/logs.rb +65 -0
- data/lib/auth0/api/v2/resource_servers.rb +61 -0
- data/lib/auth0/api/v2/rules.rb +21 -20
- data/lib/auth0/api/v2/stats.rb +2 -2
- data/lib/auth0/api/v2/tenants.rb +6 -4
- data/lib/auth0/api/v2/tickets.rb +13 -14
- data/lib/auth0/api/v2/user_blocks.rb +62 -0
- data/lib/auth0/api/v2/users.rb +63 -32
- data/lib/auth0/client.rb +0 -2
- data/lib/auth0/mixins.rb +4 -3
- data/lib/auth0/mixins/httpproxy.rb +55 -0
- data/lib/auth0/mixins/initializer.rb +27 -10
- data/lib/auth0/version.rb +1 -1
- data/spec/integration/lib/auth0/api/api_authentication_spec.rb +118 -0
- data/spec/integration/lib/auth0/api/v2/api_blacklist_spec.rb +1 -1
- data/spec/integration/lib/auth0/api/v2/api_client_grants_spec.rb +53 -0
- data/spec/integration/lib/auth0/api/v2/api_clients_spec.rb +5 -2
- data/spec/integration/lib/auth0/api/v2/api_connections_spec.rb +8 -5
- data/spec/integration/lib/auth0/api/v2/api_device_credentials_spec.rb +67 -0
- data/spec/integration/lib/auth0/api/v2/api_email_spec.rb +15 -8
- data/spec/integration/lib/auth0/api/v2/api_jobs_spec.rb +11 -9
- data/spec/integration/lib/auth0/api/v2/api_logs_spec.rb +69 -0
- data/spec/integration/lib/auth0/api/v2/api_resource_servers_spec.rb +47 -0
- data/spec/integration/lib/auth0/api/v2/api_rules_spec.rb +2 -1
- data/spec/integration/lib/auth0/api/v2/api_tickets_spec.rb +2 -2
- data/spec/integration/lib/auth0/api/v2/api_user_blocks_spec.rb +73 -0
- data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +32 -5
- data/spec/integration/lib/auth0/auth0_client_spec.rb +14 -11
- data/spec/lib/auth0/api/authentication_endpoints_spec.rb +116 -56
- data/spec/lib/auth0/api/v1/connections_spec.rb +2 -4
- data/spec/lib/auth0/api/v1/rules_spec.rb +2 -1
- data/spec/lib/auth0/api/v1/users_spec.rb +17 -9
- data/spec/lib/auth0/api/v2/client_grants_spec.rb +44 -0
- data/spec/lib/auth0/api/v2/connections_spec.rb +2 -1
- data/spec/lib/auth0/api/v2/device_credentials_spec.rb +73 -0
- data/spec/lib/auth0/api/v2/jobs_spec.rb +3 -2
- data/spec/lib/auth0/api/v2/logs_spec.rb +48 -0
- data/spec/lib/auth0/api/v2/resource_servers_spec.rb +63 -0
- data/spec/lib/auth0/api/v2/rules_spec.rb +8 -4
- data/spec/lib/auth0/api/v2/tenants_spec.rb +2 -1
- data/spec/lib/auth0/api/v2/tickets_spec.rb +4 -7
- data/spec/lib/auth0/api/v2/user_blocks_spec.rb +52 -0
- data/spec/lib/auth0/api/v2/users_spec.rb +39 -6
- data/spec/lib/auth0/client_spec.rb +8 -5
- data/spec/lib/auth0/mixins/httpproxy_spec.rb +225 -0
- data/spec/lib/auth0/mixins/initializer_spec.rb +1 -1
- data/spec/spec_helper_full.rb +12 -3
- data/spec/spec_helper_unit.rb +2 -2
- data/spec/support/credentials.rb +6 -4
- data/spec/support/dummy_class.rb +2 -1
- data/spec/support/dummy_class_for_proxy.rb +2 -2
- data/spec/support/dummy_class_for_restclient.rb +2 -0
- metadata +117 -9
- data/lib/auth0/mixins/httparty_proxy.rb +0 -38
- data/spec/lib/auth0/mixins/httparty_proxy_spec.rb +0 -148
data/lib/auth0/api/v2/rules.rb
CHANGED
|
@@ -10,10 +10,10 @@ module Auth0
|
|
|
10
10
|
# The rule's stage of executing could be set to the following values login_success,
|
|
11
11
|
# login_failure or pre_authorize
|
|
12
12
|
# @see https://auth0.com/docs/api/v2#!/Rules/get_rules
|
|
13
|
-
# @param enabled [boolean]
|
|
13
|
+
# @param enabled [boolean] If provided retrieves rules that match the value, otherwise all rules are retrieved.
|
|
14
14
|
# @param fields [string] A comma separated list of fields to include or exclude from the result.
|
|
15
|
-
# @param include_fields [boolean]
|
|
16
|
-
# @param stage [string]
|
|
15
|
+
# @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
|
|
16
|
+
# @param stage [string] Retrieves rules that match the execution stage (defaults to login_success).
|
|
17
17
|
#
|
|
18
18
|
# @return [json] Returns the existing rules.
|
|
19
19
|
def rules(enabled: nil, fields: nil, include_fields: nil, stage: nil)
|
|
@@ -26,17 +26,17 @@ module Auth0
|
|
|
26
26
|
get(rules_path, request_params)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
alias get_rules rules
|
|
30
30
|
|
|
31
31
|
# Retrieves a rule by its ID. Accepts a list of fields to include or exclude in the result.
|
|
32
32
|
# @see https://auth0.com/docs/api/v2#!/Rules/get_rules_by_id
|
|
33
|
-
# @param rule_id [string]
|
|
33
|
+
# @param rule_id [string] The id of the rule to retrieve.
|
|
34
34
|
# @param fields [string] A comma separated list of fields to include or exclude from the result.
|
|
35
|
-
# @param include_fields [boolean]
|
|
35
|
+
# @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
|
|
36
36
|
#
|
|
37
37
|
# @return [json] Returns the rule.
|
|
38
38
|
def rule(rule_id, fields: nil, include_fields: nil)
|
|
39
|
-
|
|
39
|
+
raise Auth0::InvalidParameter, 'Must supply a valid rule id' if rule_id.to_s.empty?
|
|
40
40
|
path = "#{rules_path}/#{rule_id}"
|
|
41
41
|
request_params = {
|
|
42
42
|
fields: fields,
|
|
@@ -45,22 +45,22 @@ module Auth0
|
|
|
45
45
|
get(path, request_params)
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
alias get_rule rule
|
|
49
49
|
|
|
50
50
|
# Creates a new rule according to the JSON object received in body.
|
|
51
51
|
# @see https://auth0.com/docs/api/v2#!/Rules/post_rules
|
|
52
|
-
# @param name [string]
|
|
53
|
-
# @param script [string] A script that contains the rule's code
|
|
52
|
+
# @param name [string] The name of the rule. Can only contain alphanumeric characters, spaces and '-'.
|
|
53
|
+
# @param script [string] A script that contains the rule's code.
|
|
54
54
|
# @param order [integer] The rule's order in relation to other rules. A rule with a lower order than another rule
|
|
55
|
-
# executes first. If no order is provided it will automatically be one greater than the current maximum
|
|
56
|
-
# @param enabled [string]
|
|
55
|
+
# executes first. If no order is provided it will automatically be one greater than the current maximum.
|
|
56
|
+
# @param enabled [string] True if the rule is enabled, false otherwise.
|
|
57
57
|
# @param stage [string] The rule's execution stage 'login_success' or 'login_failure' or 'pre_authorize' or
|
|
58
|
-
# 'user_registration' or 'user_blocked'
|
|
58
|
+
# 'user_registration' or 'user_blocked'.
|
|
59
59
|
#
|
|
60
|
-
# @return [json] Returns the rule.
|
|
60
|
+
# @return [json] Returns the created rule.
|
|
61
61
|
def create_rule(name, script, order = nil, enabled = true, stage = 'login_success')
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
raise Auth0::InvalidParameter, 'Must supply a valid name' if name.to_s.empty?
|
|
63
|
+
raise Auth0::InvalidParameter, 'Must supply a valid script' if script.to_s.empty?
|
|
64
64
|
request_params = {
|
|
65
65
|
name: name,
|
|
66
66
|
enabled: enabled,
|
|
@@ -73,11 +73,12 @@ module Auth0
|
|
|
73
73
|
|
|
74
74
|
# Updates a rule.
|
|
75
75
|
# @see https://auth0.com/docs/api/v2#!/Rules/patch_rules_by_id
|
|
76
|
-
# @param rule_id [string] The id of the rule to retrieve
|
|
76
|
+
# @param rule_id [string] The id of the rule to retrieve.
|
|
77
77
|
# @param fields_to_update [hash] The Hash fields_to_update used to define the rule's properties.
|
|
78
|
+
#
|
|
78
79
|
# @return [json] Returns the updated rule.
|
|
79
80
|
def update_rule(rule_id, fields_to_update = {})
|
|
80
|
-
|
|
81
|
+
raise Auth0::InvalidParameter, 'Must supply a valid rule id' if rule_id.to_s.empty?
|
|
81
82
|
|
|
82
83
|
path = "#{rules_path}/#{rule_id}"
|
|
83
84
|
patch(path, fields_to_update)
|
|
@@ -85,9 +86,9 @@ module Auth0
|
|
|
85
86
|
|
|
86
87
|
# Deletes a rule.
|
|
87
88
|
# @see https://auth0.com/docs/api/v2#!/Rules/delete_rules_by_id
|
|
88
|
-
# @param rule_id [string] The id of the rule to
|
|
89
|
+
# @param rule_id [string] The id of the rule to delete.
|
|
89
90
|
def delete_rule(rule_id)
|
|
90
|
-
|
|
91
|
+
raise Auth0::InvalidParameter, 'Must supply a valid rule id' if rule_id.to_s.empty?
|
|
91
92
|
path = "#{rules_path}/#{rule_id}"
|
|
92
93
|
delete(path)
|
|
93
94
|
end
|
data/lib/auth0/api/v2/stats.rb
CHANGED
|
@@ -8,7 +8,7 @@ module Auth0
|
|
|
8
8
|
# Gets the active users count (logged in during the last 30 days).
|
|
9
9
|
# @see https://auth0.com/docs/api/v2#!/Stats/get_active_users
|
|
10
10
|
#
|
|
11
|
-
# @return [integer] Returns
|
|
11
|
+
# @return [integer] Returns the active users count.
|
|
12
12
|
def active_users
|
|
13
13
|
path = "#{stats_path}/active-users"
|
|
14
14
|
get(path)
|
|
@@ -16,7 +16,7 @@ module Auth0
|
|
|
16
16
|
|
|
17
17
|
# Gets the daily stats for a particular period.
|
|
18
18
|
# @see https://auth0.com/docs/api/v2#!/Stats/get_daily
|
|
19
|
-
# @param from [string]
|
|
19
|
+
# @param from [string] The first day of the period (inclusive) in YYYYMMDD format.
|
|
20
20
|
# @param to [string] The last day of the period (inclusive) in YYYYMMDD format.
|
|
21
21
|
#
|
|
22
22
|
# @return [json] Returns the daily stats.
|
data/lib/auth0/api/v2/tenants.rb
CHANGED
|
@@ -8,7 +8,8 @@ module Auth0
|
|
|
8
8
|
# Gets tenants settings.
|
|
9
9
|
# @see https://auth0.com/docs/api/v2#!/Tenants/get_settings
|
|
10
10
|
# @param fields [string] A comma separated list of fields to include or exclude from the result.
|
|
11
|
-
# @param include_fields [boolean]
|
|
11
|
+
# @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
|
|
12
|
+
#
|
|
12
13
|
# @return [json] Returns tenants settings.
|
|
13
14
|
def get_tenant_settings(fields: nil, include_fields: true)
|
|
14
15
|
request_params = {
|
|
@@ -20,10 +21,11 @@ module Auth0
|
|
|
20
21
|
|
|
21
22
|
# Updates tenants settings.
|
|
22
23
|
# @see https://auth0.com/docs/api/v2#!/Tenants/patch_settings
|
|
23
|
-
# @param body [hash] The Hash body used to define the
|
|
24
|
-
#
|
|
24
|
+
# @param body [hash] The Hash body used to define the tenant settings' values.
|
|
25
|
+
#
|
|
26
|
+
# @return [json] Returns the updated tenant settings.
|
|
25
27
|
def update_tenant_settings(body)
|
|
26
|
-
|
|
28
|
+
raise Auth0::InvalidParameter, 'Must supply a valid body to update tenant settings' if body.to_s.empty?
|
|
27
29
|
patch(tenant_path, body)
|
|
28
30
|
end
|
|
29
31
|
|
data/lib/auth0/api/v2/tickets.rb
CHANGED
|
@@ -7,12 +7,13 @@ module Auth0
|
|
|
7
7
|
|
|
8
8
|
# Create an email verification ticket
|
|
9
9
|
# @see https://auth0.com/docs/api/v2#!/Tickets/post_email_verification
|
|
10
|
-
# @param user_id [string] The user_id of for which the ticket is to be created
|
|
11
|
-
# @param result_url [string] The user will be redirected to this endpoint once the ticket is used
|
|
12
|
-
#
|
|
10
|
+
# @param user_id [string] The user_id of for which the ticket is to be created.
|
|
11
|
+
# @param result_url [string] The user will be redirected to this endpoint once the ticket is used.
|
|
12
|
+
#
|
|
13
|
+
# @return [json] Returns the created ticket url.
|
|
13
14
|
def post_email_verification(user_id, result_url: nil)
|
|
14
15
|
if user_id.to_s.empty?
|
|
15
|
-
|
|
16
|
+
raise Auth0::InvalidParameter, 'Must supply a valid user id to post an email verification'
|
|
16
17
|
end
|
|
17
18
|
path = "#{tickets_path}/email-verification"
|
|
18
19
|
request_params = {
|
|
@@ -24,17 +25,15 @@ module Auth0
|
|
|
24
25
|
|
|
25
26
|
# Create a password change ticket
|
|
26
27
|
# @see https://auth0.com/docs/api/v2#!/Tickets/post_password_change
|
|
27
|
-
# @param new_password [string] The password to set for the user once the ticket is used
|
|
28
|
-
# @param user_id [string] The user_id of for which the ticket is to be created
|
|
29
|
-
# @param result_url [string] The user will be redirected to this endpoint once the ticket is used
|
|
28
|
+
# @param new_password [string] The password to be set for the user once the ticket is used.
|
|
29
|
+
# @param user_id [string] The user_id of for which the ticket is to be created.
|
|
30
|
+
# @param result_url [string] The user will be redirected to this endpoint once the ticket is used.
|
|
30
31
|
# @param connection_id [string] The connection that provides the identity for which the password is to be
|
|
31
|
-
# changed. If sending this parameter, the email is also required and the user_id is invalid
|
|
32
|
-
# @param email [string] The user's email
|
|
33
|
-
#
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
fail Auth0::InvalidParameter, 'Must supply a valid new password to post a password-change'
|
|
37
|
-
end
|
|
32
|
+
# changed. If sending this parameter, the email is also required and the user_id is invalid.
|
|
33
|
+
# @param email [string] The user's email.
|
|
34
|
+
#
|
|
35
|
+
# @return [json] Returns the created ticket url.
|
|
36
|
+
def post_password_change(new_password: nil, user_id: nil, result_url: nil, connection_id: nil, email: nil)
|
|
38
37
|
path = "#{tickets_path}/password-change"
|
|
39
38
|
request_params = {
|
|
40
39
|
user_id: user_id,
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Auth0
|
|
2
|
+
module Api
|
|
3
|
+
module V2
|
|
4
|
+
# Methods to use the User Blocks endpoints
|
|
5
|
+
module UserBlocks
|
|
6
|
+
attr_reader :user_blocks_path
|
|
7
|
+
|
|
8
|
+
# Retrieves the user blocks
|
|
9
|
+
# @see https://auth0.com/docs/api/management/v2#!/User_Blocks/get_user_blocks
|
|
10
|
+
# @param identifier [string] Should be any of: username, phone_number, email.
|
|
11
|
+
#
|
|
12
|
+
# @return [json] the user blocks
|
|
13
|
+
def user_blocks(identifier)
|
|
14
|
+
raise Auth0::InvalidParameter, 'Must specify a valid identifier' if identifier.to_s.empty?
|
|
15
|
+
request_params = {
|
|
16
|
+
identifier: identifier
|
|
17
|
+
}
|
|
18
|
+
get(user_blocks_path, request_params)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Deletes the user blocks
|
|
22
|
+
# @see https://auth0.com/docs/api/management/v2#!/User_Blocks/delete_user_blocks
|
|
23
|
+
# @param identifier [string] Should be any of: username, phone_number, email.
|
|
24
|
+
def delete_user_blocks(identifier)
|
|
25
|
+
raise Auth0::InvalidParameter, 'Must specify a valid identifier' if identifier.to_s.empty?
|
|
26
|
+
# path = "#{user_blocks_path}?identifier=#{identifier}"
|
|
27
|
+
request_params = {
|
|
28
|
+
identifier: identifier
|
|
29
|
+
}
|
|
30
|
+
delete(user_blocks_path, request_params)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Retrieves a user's blocks
|
|
34
|
+
# @see https://auth0.com/docs/api/management/v2#!/User_Blocks/get_user_blocks_by_id
|
|
35
|
+
# @param user_id [string] The user_id of the user to retrieve
|
|
36
|
+
#
|
|
37
|
+
# @return [json] the user blocks
|
|
38
|
+
def user_blocks_by_id(user_id)
|
|
39
|
+
raise Auth0::InvalidParameter, 'Must specify a valid identifier' if user_id.to_s.empty?
|
|
40
|
+
path = "#{user_blocks_path}/#{user_id}"
|
|
41
|
+
get(path)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Deletes a user's blocks
|
|
45
|
+
# @see https://auth0.com/docs/api/management/v2#!/User_Blocks/delete_user_blocks_by_id
|
|
46
|
+
# @param user_id [string] The user_id of the user to retrieve
|
|
47
|
+
def delete_user_blocks_by_id(user_id)
|
|
48
|
+
raise Auth0::InvalidParameter, 'Must specify a valid identifier' if user_id.to_s.empty?
|
|
49
|
+
path = "#{user_blocks_path}/#{user_id}"
|
|
50
|
+
delete(path)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
# User Blocks API path
|
|
56
|
+
def user_blocks_path
|
|
57
|
+
@user_blocks_path ||= '/api/v2/user-blocks'
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
data/lib/auth0/api/v2/users.rb
CHANGED
|
@@ -7,17 +7,17 @@ module Auth0
|
|
|
7
7
|
|
|
8
8
|
# Retrieves a list of existing users.
|
|
9
9
|
# @see https://auth0.com/docs/api/v2#!/Users/get_users
|
|
10
|
-
# @param per_page [integer] The amount of entries per page. Default: 50. Max value: 100
|
|
11
|
-
# @param page [integer] The page number. Zero based
|
|
12
|
-
# @param include_totals [boolean]
|
|
13
|
-
# @param sort [string] The field to use for sorting. 1 == ascending and -1 == descending
|
|
14
|
-
# @param connection [string] Connection filter
|
|
10
|
+
# @param per_page [integer] The amount of entries per page. Default: 50. Max value: 100.
|
|
11
|
+
# @param page [integer] The page number. Zero based.
|
|
12
|
+
# @param include_totals [boolean] True if a query summary must be included in the result.
|
|
13
|
+
# @param sort [string] The field to use for sorting. 1 == ascending and -1 == descending.
|
|
14
|
+
# @param connection [string] Connection filter.
|
|
15
15
|
# @param fields [string] A comma separated list of fields to include or exclude from the result.
|
|
16
|
-
# @param include_fields [boolean] if the fields specified are to be included in the result, false otherwise.
|
|
16
|
+
# @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
|
|
17
17
|
# @param q [string] Query in Lucene query string syntax. Only fields in app_metadata, user_metadata or the
|
|
18
18
|
# normalized user profile are searchable.
|
|
19
19
|
#
|
|
20
|
-
# @return [json]
|
|
20
|
+
# @return [json] Returns the list of existing users.
|
|
21
21
|
def users(options = {})
|
|
22
22
|
request_params = {
|
|
23
23
|
per_page: options.fetch(:per_page, nil),
|
|
@@ -32,16 +32,16 @@ module Auth0
|
|
|
32
32
|
request_params[:search_engine] = :v2 if request_params[:q]
|
|
33
33
|
get(users_path, request_params)
|
|
34
34
|
end
|
|
35
|
-
|
|
35
|
+
alias get_users users
|
|
36
36
|
|
|
37
37
|
# Creates a new user according to optional parameters received.
|
|
38
38
|
# The attribute connection is always mandatory but depending on the type of connection you are using there
|
|
39
39
|
# could be others too. For instance, Auth0 DB Connections require email and password.
|
|
40
40
|
# @see https://auth0.com/docs/api/v2#!/Users/post_users
|
|
41
|
-
# @param name [string]
|
|
42
|
-
# @param connection [string] The connection the user belongs to
|
|
41
|
+
# @param name [string] The user name.
|
|
42
|
+
# @param connection [string] The connection the user belongs to.
|
|
43
43
|
#
|
|
44
|
-
# @return [json]
|
|
44
|
+
# @return [json] Returns the created user.
|
|
45
45
|
def create_user(name, options = {})
|
|
46
46
|
request_params = Hash[options.map { |(k, v)| [k.to_sym, v] }]
|
|
47
47
|
request_params[:name] = name
|
|
@@ -56,13 +56,13 @@ module Auth0
|
|
|
56
56
|
|
|
57
57
|
# Retrieves a user given a user_id
|
|
58
58
|
# @see https://auth0.com/docs/api/v2#!/Users/get_users_by_id
|
|
59
|
-
# @param user_id [string] The user_id of the user to retrieve
|
|
59
|
+
# @param user_id [string] The user_id of the user to retrieve.
|
|
60
60
|
# @param fields [string] A comma separated list of fields to include or exclude from the result.
|
|
61
|
-
# @param include_fields [boolean] if the fields specified are to be included in the result, false otherwise.
|
|
61
|
+
# @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
|
|
62
62
|
#
|
|
63
|
-
# @return [json] the user with the given user_id if exists
|
|
63
|
+
# @return [json] Returns the user with the given user_id if it exists.
|
|
64
64
|
def user(user_id, fields: nil, include_fields: true)
|
|
65
|
-
|
|
65
|
+
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
|
|
66
66
|
path = "#{users_path}/#{user_id}"
|
|
67
67
|
request_params = {
|
|
68
68
|
fields: fields,
|
|
@@ -73,9 +73,9 @@ module Auth0
|
|
|
73
73
|
|
|
74
74
|
# Deletes a single user given its id
|
|
75
75
|
# @see https://auth0.com/docs/api/v2#!/Users/delete_users_by_id
|
|
76
|
-
# @param user_id [string] The user_id of the user to delete
|
|
76
|
+
# @param user_id [string] The user_id of the user to delete.
|
|
77
77
|
def delete_user(user_id)
|
|
78
|
-
|
|
78
|
+
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
|
|
79
79
|
path = "#{users_path}/#{user_id}"
|
|
80
80
|
delete(path)
|
|
81
81
|
end
|
|
@@ -93,23 +93,23 @@ module Auth0
|
|
|
93
93
|
# If your are updating email or phone_number you need to specify the connection and the client_id properties.
|
|
94
94
|
# @see https://auth0.com/docs/api/v2#!/Users/patch_users_by_id
|
|
95
95
|
# @param user_id [string] The user_id of the user to update.
|
|
96
|
-
# @param body [hash] The optional parametes to update
|
|
96
|
+
# @param body [hash] The optional parametes to update.
|
|
97
97
|
#
|
|
98
|
-
# @return [json] the updated user
|
|
98
|
+
# @return [json] Returns the updated user.
|
|
99
99
|
def patch_user(user_id, body)
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
|
|
101
|
+
raise Auth0::InvalidParameter, 'Must supply a valid body' if body.to_s.empty?
|
|
102
102
|
path = "#{users_path}/#{user_id}"
|
|
103
103
|
patch(path, body)
|
|
104
104
|
end
|
|
105
105
|
|
|
106
106
|
# Delete a user's multifactor provider
|
|
107
107
|
# @see https://auth0.com/docs/api/v2#!/Users/delete_multifactor_by_provider
|
|
108
|
-
# @param user_id [string] The user_id of the user to delete
|
|
109
|
-
# @param provider_name [string] The multifactor provider. Supported values 'duo' or 'google-authenticator'
|
|
108
|
+
# @param user_id [string] The user_id of the user to delete the multifactor provider from.
|
|
109
|
+
# @param provider_name [string] The multifactor provider. Supported values 'duo' or 'google-authenticator'.
|
|
110
110
|
def delete_user_provider(user_id, provider_name)
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
|
|
112
|
+
raise Auth0::InvalidParameter, 'Must supply a valid provider name' if provider_name.to_s.empty?
|
|
113
113
|
path = "#{users_path}/#{user_id}/multifactor/#{provider_name}"
|
|
114
114
|
delete(path)
|
|
115
115
|
end
|
|
@@ -126,10 +126,10 @@ module Auth0
|
|
|
126
126
|
# @param user_id [string] The user_id of the primary identity where you are linking the secondary account to.
|
|
127
127
|
# @param body [string] the options to link the account to.
|
|
128
128
|
#
|
|
129
|
-
# @return [json] the new array of the primary account identities.
|
|
129
|
+
# @return [json] Returns the new array of the primary account identities.
|
|
130
130
|
def link_user_account(user_id, body)
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
|
|
132
|
+
raise Auth0::InvalidParameter, 'Must supply a valid body' if body.to_s.empty?
|
|
133
133
|
path = "#{users_path}/#{user_id}/identities"
|
|
134
134
|
post(path, body)
|
|
135
135
|
end
|
|
@@ -140,15 +140,46 @@ module Auth0
|
|
|
140
140
|
# @param provider [string] The type of identity provider.
|
|
141
141
|
# @param secondary_user_id [string] The unique identifier for the user for the identity.
|
|
142
142
|
#
|
|
143
|
-
# @return [json] the array of the unlinked account identities.
|
|
143
|
+
# @return [json] Returns the array of the unlinked account identities.
|
|
144
144
|
def unlink_users_account(user_id, provider, secondary_user_id)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
|
|
146
|
+
raise Auth0::MissingUserId, 'Must supply a valid secondary user_id' if secondary_user_id.to_s.empty?
|
|
147
|
+
raise Auth0::InvalidParameter, 'Must supply a valid provider' if provider.to_s.empty?
|
|
148
148
|
path = "#{users_path}/#{user_id}/identities/#{provider}/#{secondary_user_id}"
|
|
149
149
|
delete(path)
|
|
150
150
|
end
|
|
151
151
|
|
|
152
|
+
# Retrieve every log event for a specific user id
|
|
153
|
+
# @see https://auth0.com/docs/api/management/v2#!/Users/get_logs_by_user
|
|
154
|
+
# @param user_id [string] The user_id of the logs to retrieve.
|
|
155
|
+
# @param per_page [integer] The amount of entries per page. Default: 50. Max value: 100.
|
|
156
|
+
# @param page [integer] The page number. Zero based.
|
|
157
|
+
# @param include_totals [boolean] True if a query summary must be included in the result.
|
|
158
|
+
# @param sort [string] The field to use for sorting. 1 == ascending and -1 == descending.
|
|
159
|
+
#
|
|
160
|
+
# @return [json] Returns the list of existing log entries for the given user_id.
|
|
161
|
+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
|
162
|
+
def user_logs(user_id, options = {})
|
|
163
|
+
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
|
|
164
|
+
path = "#{users_path}/#{user_id}/logs"
|
|
165
|
+
request_params = {
|
|
166
|
+
user_id: user_id,
|
|
167
|
+
per_page: options.fetch(:per_page, nil),
|
|
168
|
+
page: options.fetch(:page, nil),
|
|
169
|
+
include_totals: options.fetch(:include_totals, nil),
|
|
170
|
+
sort: options.fetch(:sort, nil)
|
|
171
|
+
}
|
|
172
|
+
if request_params[:per_page].to_i > 100
|
|
173
|
+
raise Auth0::InvalidParameter, 'The total amount of entries per page should be less than 100'
|
|
174
|
+
end
|
|
175
|
+
sort_pattern = /^(([a-zA-Z0-9_\.]+))\:(1|-1)$/
|
|
176
|
+
if !request_params[:sort].nil? && !sort_pattern.match(request_params[:sort])
|
|
177
|
+
raise Auth0::InvalidParameter, 'Sort does not match pattern ^(([a-zA-Z0-9_\\.]+))\\:(1|-1)$'
|
|
178
|
+
end
|
|
179
|
+
get(path, request_params)
|
|
180
|
+
end
|
|
181
|
+
alias get_user_log_events user_logs
|
|
182
|
+
|
|
152
183
|
private
|
|
153
184
|
|
|
154
185
|
# Users API path
|
data/lib/auth0/client.rb
CHANGED
data/lib/auth0/mixins.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'base64'
|
|
2
|
+
require 'rest-client'
|
|
2
3
|
require 'uri'
|
|
3
|
-
require 'auth0/mixins/
|
|
4
|
+
require 'auth0/mixins/httpproxy'
|
|
4
5
|
require 'auth0/mixins/initializer'
|
|
5
6
|
require 'auth0/api/authentication_endpoints'
|
|
6
7
|
require 'auth0/api/v1'
|
|
@@ -8,7 +9,7 @@ require 'auth0/api/v2'
|
|
|
8
9
|
module Auth0
|
|
9
10
|
# Collecting dependencies here
|
|
10
11
|
module Mixins
|
|
11
|
-
include Auth0::Mixins::
|
|
12
|
+
include Auth0::Mixins::HTTPProxy
|
|
12
13
|
include Auth0::Mixins::Initializer
|
|
13
14
|
end
|
|
14
15
|
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module Auth0
|
|
2
|
+
module Mixins
|
|
3
|
+
# here's the proxy for Rest calls based on rest-client, we're building all request on that gem
|
|
4
|
+
# for now, if you want to feel free to use your own http client
|
|
5
|
+
module HTTPProxy
|
|
6
|
+
attr_accessor :headers, :base_uri, :timeout
|
|
7
|
+
|
|
8
|
+
# proxying requests from instance methods to HTTP class methods
|
|
9
|
+
%i(get post post_file put patch delete).each do |method|
|
|
10
|
+
define_method(method) do |path, body = {}|
|
|
11
|
+
safe_path = URI.escape(path)
|
|
12
|
+
body = body.delete_if { |_, v| v.nil? }
|
|
13
|
+
result = if [:get, :delete].include?(method)
|
|
14
|
+
call(method, url(safe_path), timeout, add_headers(params: body))
|
|
15
|
+
elsif method == :post_file
|
|
16
|
+
call(:post, url(safe_path), timeout, headers, body)
|
|
17
|
+
else
|
|
18
|
+
call(method, url(safe_path), timeout, headers, body.to_json)
|
|
19
|
+
end
|
|
20
|
+
case result.code
|
|
21
|
+
when 200...226 then safe_parse_json(result.body)
|
|
22
|
+
when 400 then raise Auth0::BadRequest, result.to_s
|
|
23
|
+
when 401 then raise Auth0::Unauthorized, result.body
|
|
24
|
+
when 403 then raise Auth0::AccessDenied, result.body
|
|
25
|
+
when 404 then raise Auth0::NotFound, result.body
|
|
26
|
+
when 500 then raise Auth0::ServerError, result.body
|
|
27
|
+
else raise Auth0::Unsupported, result.body
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def url(path)
|
|
33
|
+
"#{base_uri}#{path}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def add_headers(h = {})
|
|
37
|
+
raise ArgumentError, 'Headers must be an object which responds to #to_hash' unless h.respond_to?(:to_hash)
|
|
38
|
+
@headers ||= {}
|
|
39
|
+
@headers.merge!(h.to_hash)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def safe_parse_json(body)
|
|
43
|
+
JSON.parse(body.to_s)
|
|
44
|
+
rescue JSON::ParserError
|
|
45
|
+
body
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def call(method, url, timeout, headers, body = nil)
|
|
49
|
+
RestClient::Request.execute(method: method, url: url, timeout: timeout, headers: headers, payload: body)
|
|
50
|
+
rescue RestClient::Exception => e
|
|
51
|
+
e.response
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|