auth0 4.7.0 → 4.12.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.
Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +23 -0
  3. data/.env.example +2 -0
  4. data/.github/CODEOWNERS +1 -0
  5. data/.github/stale.yml +20 -0
  6. data/.gitignore +0 -1
  7. data/.rubocop.yml +2 -0
  8. data/CHANGELOG.md +83 -0
  9. data/DEPLOYMENT.md +25 -3
  10. data/Gemfile +3 -1
  11. data/Gemfile.lock +231 -0
  12. data/README.md +114 -25
  13. data/auth0.gemspec +6 -6
  14. data/codecov.yml +22 -0
  15. data/deploy_documentation.sh +1 -1
  16. data/lib/auth0.rb +1 -0
  17. data/lib/auth0/algorithm.rb +5 -0
  18. data/lib/auth0/api/authentication_endpoints.rb +38 -2
  19. data/lib/auth0/api/v2.rb +6 -0
  20. data/lib/auth0/api/v2/anomaly.rb +36 -0
  21. data/lib/auth0/api/v2/client_grants.rb +5 -1
  22. data/lib/auth0/api/v2/guardian.rb +142 -0
  23. data/lib/auth0/api/v2/jobs.rb +22 -3
  24. data/lib/auth0/api/v2/roles.rb +172 -0
  25. data/lib/auth0/api/v2/users.rb +115 -4
  26. data/lib/auth0/exception.rb +35 -7
  27. data/lib/auth0/mixins.rb +8 -3
  28. data/lib/auth0/mixins/httpproxy.rb +11 -8
  29. data/lib/auth0/mixins/permission_struct.rb +3 -0
  30. data/lib/auth0/mixins/validation.rb +340 -0
  31. data/lib/auth0/version.rb +1 -1
  32. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Anomaly/_check_if_ip_is_blocked/should_return_200_response_code.yml +65 -0
  33. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Anomaly/_remove_ip_block/should_remove_an_IP_successfully.yml +60 -0
  34. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_at_least_1_result.yml +1 -1
  35. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_the_first_page_of_one_result.yml +1 -1
  36. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_the_test_client_grant.yml +1 -1
  37. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_delete_client_grant/should_delete_the_test_client_grant.yml +1 -1
  38. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_patch_client_grant/should_update_the_test_client_grant.yml +1 -1
  39. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/create_test_client.yml +1 -1
  40. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/create_test_client_grant.yml +1 -1
  41. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/delete_test_client.yml +1 -1
  42. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/delete_test_client_grant.yml +1 -1
  43. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/_filters/should_exclude_and_include_fields_properly.yml +1 -1
  44. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/_filters/should_include_the_specified_fields.yml +1 -1
  45. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/should_get_the_test_client.yml +1 -1
  46. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_exclude_fields_not_specified.yml +1 -1
  47. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_exclude_the_specified_fields.yml +1 -1
  48. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_include_the_specified_fields.yml +1 -1
  49. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_paginate_results.yml +1 -1
  50. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/should_get_at_least_one_client.yml +1 -1
  51. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_delete_client/should_delete_the_test_client_without_an_error.yml +1 -1
  52. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_patch_client/should_update_the_client_with_the_correct_attributes.yml +1 -1
  53. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/create_test_client.yml +1 -1
  54. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/_filters/should_exclude_the_fields_indicated.yml +1 -1
  55. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/_filters/should_include_the_fields_indicated.yml +1 -1
  56. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/should_find_the_correct_connection.yml +1 -1
  57. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_include_previously-created_connection_when_filtered.yml +1 -1
  58. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_should_exclude_the_fields_indicated_from_filtered_results.yml +1 -1
  59. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_should_include_the_fields_indicated_from_filtered_results.yml +1 -1
  60. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/should_include_the_previously_created_connection.yml +1 -1
  61. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/should_not_be_empty.yml +1 -1
  62. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_delete_connection/should_delete_the_connection.yml +1 -1
  63. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_delete_connection_user/should_delete_the_user_created.yml +2 -2
  64. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_update_connection/should_update_the_connection.yml +1 -1
  65. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/create_test_connection.yml +1 -1
  66. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/create_test_user.yml +1 -1
  67. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/create_test_user.yml +1 -1
  68. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/delete_test_credential.yml +1 -1
  69. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/delete_test_user.yml +1 -1
  70. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_configure_provider/should_configure_a_new_email_provider.yml +1 -1
  71. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_delete_provider/should_delete_the_existing_email_provider_without_an_error.yml +1 -1
  72. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_delete_provider/should_throw_an_error_trying_to_get_the_email_provider.yml +1 -1
  73. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/_filters/should_get_the_existing_email_provider_with_specific_fields.yml +1 -1
  74. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/_filters/should_get_the_existing_email_provider_without_specific_fields.yml +1 -1
  75. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/should_get_the_existing_email_provider.yml +1 -1
  76. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_update_provider/should_update_the_existing_email_provider.yml +1 -1
  77. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/delete_existing_provider.yml +1 -1
  78. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_log/should_match_the_created_log_entry.yml +2 -2
  79. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_log/should_not_be_empty.yml +2 -2
  80. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_exclude_fields_not_specified.yml +1 -1
  81. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_exclude_the_specified_fields.yml +1 -1
  82. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_have_one_log_entry.yml +1 -1
  83. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_include_the_specified_fields.yml +1 -1
  84. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_from/should_take_one_log_entry.yml +2 -2
  85. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/create_test_user.yml +1 -1
  86. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_disabled_rule.yml +1 -1
  87. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_enabled_rule.yml +1 -1
  88. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_user.yml +1 -1
  89. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_add_role_permissions/should_add_a_Permission_to_the_Role_successfully.yml +69 -0
  90. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_add_role_users/should_add_a_User_to_the_Role_successfully.yml +69 -0
  91. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_delete_role/should_delete_the_Role_successfully.yml +62 -0
  92. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role/should_get_the_Role_successfully.yml +67 -0
  93. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_permissions/should_get_exactly_1_Permission.yml +67 -0
  94. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_permissions/should_get_the_added_Permission_from_the_Role_successfully.yml +67 -0
  95. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_users/should_get_exactly_1_User.yml +67 -0
  96. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_users/should_get_the_added_User_from_the_Role_successfully.yml +67 -0
  97. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_roles/should_get_the_Role_successfully.yml +67 -0
  98. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_remove_role_permissions/should_remove_a_Permission_from_the_Role_successfully.yml +64 -0
  99. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_update_role/should_update_the_Role_successfully.yml +69 -0
  100. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_api.yml +69 -0
  101. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_role.yml +69 -0
  102. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_user.yml +69 -0
  103. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/delete_test_api.yml +62 -0
  104. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/delete_test_user.yml +62 -0
  105. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_delete_rule/should_delete_the_test_disabled_rule_without_an_error.yml +1 -1
  106. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_delete_rule/should_delete_the_test_enabled_rule_without_an_error.yml +1 -1
  107. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_exclude_the_fields_not_specified.yml +1 -1
  108. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_exclude_the_specified_fields.yml +1 -1
  109. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_include_the_specified_fields.yml +1 -1
  110. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/should_get_a_specific_rule.yml +1 -1
  111. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_exclude_fields_not_specified.yml +1 -1
  112. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_include_the_specified_fields.yml +1 -1
  113. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_at_least_1_disabled_rule.yml +1 -1
  114. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_at_least_1_enabled_rule.yml +1 -1
  115. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_paginated_results.yml +2 -2
  116. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/should_return_at_least_1_rule.yml +1 -1
  117. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_update_rule/should_update_the_disabled_rule_to_be_enabled.yml +1 -1
  118. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/create_test_disabled_rule.yml +1 -1
  119. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/create_test_enabled_rule.yml +1 -1
  120. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Stats/_active_users/should_have_at_least_one_active_user.yml +1 -1
  121. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Stats/_daily_stats/should_have_at_least_one_stats_entry_for_the_timeframe.yml +1 -1
  122. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings/should_get_the_tenant_settings.yml +1 -1
  123. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings_with_specific_fields/should_exclude_a_field_not_requested.yml +1 -1
  124. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings_with_specific_fields/should_include_the_field_requested.yml +1 -1
  125. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_update_tenant_settings/should_revert_the_tenant_name.yml +1 -1
  126. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_update_tenant_settings/should_update_the_tenant_settings_with_a_new_tenant_name.yml +1 -1
  127. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/_post_email_verification/should_create_an_email_verification_ticket.yml +1 -1
  128. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/_post_password_change/should_create_a_password_change_ticket.yml +1 -1
  129. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/create_test_user.yml +1 -1
  130. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/delete_test_user.yml +1 -1
  131. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_add_user_permissions/should_add_a_Permissions_for_a_User_successfully.yml +67 -0
  132. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_add_user_roles/should_add_a_Role_to_a_User_successfully.yml +62 -0
  133. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_delete_user/{should_delete_the_user_successfully.yml → should_delete_the_User_successfully.yml} +14 -8
  134. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_delete_user/should_delete_the_secondary_User_successfully.yml +60 -0
  135. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_delete_user_provider/should_attempt_to_delete_the_MFA_provider_for_the_User.yml +60 -0
  136. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_enrollments/should_get_Enrollments_for_a_User_successfully.yml +65 -0
  137. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_permissions/should_get_exactly_1_Permission_for_a_User_successfully.yml +65 -0
  138. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_permissions/should_get_the_correct_Permission_for_a_User_successfully.yml +65 -0
  139. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_roles/should_get_Roles_for_a_User_successfully.yml +65 -0
  140. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_invalidate_browsers/should_invalidate_MFA_browsers_for_the_User_successfully.yml +62 -0
  141. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_link_user_account/should_link_two_Users_successfully.yml +67 -0
  142. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_patch_user/should_patch_the_User_successfully.yml +68 -0
  143. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_remove_user_permissions/should_remove_a_Permission_from_a_User_successfully.yml +62 -0
  144. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_remove_user_roles/should_remove_a_Role_from_a_User_successfully.yml +62 -0
  145. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_unlink_user_account/should_unlink_two_Users_successfully.yml +65 -0
  146. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_exclude_fields_not_indicated.yml +15 -10
  147. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_exclude_the_fields_indicated.yml +15 -13
  148. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_include_the_fields_indicated.yml +15 -13
  149. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/should_retrieve_the_created_user.yml +15 -16
  150. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user_logs/should_get_Logs_for_a_User_successfully.yml +69 -0
  151. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/is_expected_to_find_a_user_with_a_v2_search_engine_query.yml +14 -8
  152. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/is_expected_to_find_a_user_with_a_v3_search_engine_query.yml +14 -8
  153. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_exclude_the_indicated_fields_when_paginated.yml +13 -7
  154. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_include_the_indicated_fields_when_paginated.yml +13 -7
  155. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_not_include_other_fields_when_paginated.yml +13 -7
  156. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_return_the_correct_number_of_results_when_paginated.yml +13 -7
  157. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/should_have_at_least_one_user.yml +13 -7
  158. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_secondary_test_user.yml +67 -0
  159. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_api.yml +67 -0
  160. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_role.yml +67 -0
  161. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_user.yml +15 -16
  162. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/delete_test_api.yml +60 -0
  163. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/delete_test_role.yml +60 -0
  164. data/spec/integration/lib/auth0/api/v2/api_anomaly_spec.rb +17 -0
  165. data/spec/integration/lib/auth0/api/v2/api_roles_spec.rb +145 -0
  166. data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +150 -32
  167. data/spec/integration/lib/auth0/auth0_client_spec.rb +3 -4
  168. data/spec/lib/auth0/api/authentication_endpoints_spec.rb +37 -10
  169. data/spec/lib/auth0/api/v2/anomaly_spec.rb +26 -0
  170. data/spec/lib/auth0/api/v2/client_grants_spec.rb +17 -0
  171. data/spec/lib/auth0/api/v2/guardian_spec.rb +154 -0
  172. data/spec/lib/auth0/api/v2/jobs_spec.rb +33 -1
  173. data/spec/lib/auth0/api/v2/roles_spec.rb +362 -0
  174. data/spec/lib/auth0/api/v2/users_spec.rb +406 -66
  175. data/spec/lib/auth0/mixins/httpproxy_spec.rb +81 -2
  176. data/spec/lib/auth0/mixins/validation_spec.rb +474 -0
  177. data/spec/spec_helper.rb +11 -7
  178. data/spec/support/credentials.rb +4 -13
  179. data/spec/support/dummy_class.rb +1 -1
  180. data/spec/support/stub_response.rb +1 -1
  181. metadata +145 -23
  182. data/.travis.yml +0 -18
  183. data/build_travis.sh +0 -7
  184. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_patch_user/should_patch_email_verified_and_return_the_updated_data.yml +0 -68
  185. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_patch_user/should_patch_user_metadata_and_return_the_updated_user.yml +0 -69
@@ -15,20 +15,39 @@ module Auth0
15
15
  get(path)
16
16
  end
17
17
 
18
+ # Retrieve error details based on the id of the job. Useful to check its status.
19
+ # @see https://auth0.com/docs/api/management/v2#!/Jobs/get_errors
20
+ # @param job_id [string] The ID of the job.
21
+ #
22
+ # @return [json] Returns the job error details.
23
+ def get_job_errors(job_id)
24
+ raise Auth0::InvalidParameter, 'Must specify a job id' if job_id.to_s.empty?
25
+
26
+ path = "#{jobs_path}/#{job_id}/errors"
27
+ get(path)
28
+ end
29
+
18
30
  # Imports users to a connection from a file using a long running job.
19
31
  # Documentation for the file format: https://docs.auth0.com/bulk-import
20
32
  # @see https://auth0.com/docs/api/v2#!/Jobs/post_users_imports
21
33
  # @param users_file [file] A file containing the users to import.
22
34
  # @param connection_id [string] Database connection ID to import to.
23
- #
35
+ # @param options [hash]
36
+ # * :upsert [boolean] Update the user if already exists. False by default.
37
+ # * :external_id [string] Customer defined id
38
+ # * :send_completion_email [boolean] If true,
39
+ # send the completion email to all tenant owners when the job is finished. True by default.
24
40
  # @return [json] Returns the job status and properties.
25
- def import_users(users_file, connection_id)
41
+ def import_users(users_file, connection_id, options = {})
26
42
  raise Auth0::InvalidParameter, 'Must specify a valid file' if users_file.to_s.empty?
27
43
  raise Auth0::InvalidParameter, 'Must specify a connection_id' if connection_id.to_s.empty?
28
44
 
29
45
  request_params = {
30
46
  users: users_file,
31
- connection_id: connection_id
47
+ connection_id: connection_id,
48
+ upsert: options.fetch(:upsert, false),
49
+ external_id: options.fetch(:external_id, nil),
50
+ send_completion_email: options.fetch(:send_completion_email, true)
32
51
  }
33
52
  path = "#{jobs_path}/users-imports"
34
53
  post_file(path, request_params)
@@ -0,0 +1,172 @@
1
+ module Auth0
2
+ module Api
3
+ module V2
4
+ # Methods to use the Roles endpoints
5
+ module Roles
6
+ include Auth0::Mixins::Validation
7
+
8
+ # Get all Roles
9
+ # Required scope: "read:roles"
10
+ # @see https://auth0.com/docs/api/management/v2#!/Roles/get_roles
11
+ #
12
+ # @param options [hash] A hash of options for getting Roles
13
+ # - per_page: Number of Roles to return.
14
+ # - page: Page number to return, zero-based.
15
+ # - include_totals: True to include query summary in the result, false or nil otherwise.
16
+ # - name_filter: Optional filter on name (case-insensitive).
17
+ #
18
+ # @return [json] All Roles matching the query.
19
+ def get_roles(options = {})
20
+ request_params = {
21
+ per_page: options.fetch(:per_page, nil),
22
+ page: options.fetch(:page, nil),
23
+ include_totals: options.fetch(:include_totals, nil),
24
+ name_filter: options.fetch(:name_filter, nil)
25
+ }
26
+ get roles_path, request_params
27
+ end
28
+ alias roles get_roles
29
+
30
+ # Get a single Role by ID.
31
+ # Required scope: "read:roles"
32
+ # @see https://auth0.com/docs/api/management/v2#!/Roles/get_roles_by_id
33
+ #
34
+ # @param role_id [string] Role ID to get.
35
+ #
36
+ # @return [json] Role data.
37
+ def get_role(role_id)
38
+ raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty?
39
+
40
+ get "#{roles_path}/#{role_id}"
41
+ end
42
+ alias role get_role
43
+
44
+ # Create a new Role.
45
+ # Required scope: "create:roles"
46
+ # @see https://auth0.com/docs/api/management/v2#!/Roles/post_roles
47
+ #
48
+ # @param role_name [string] Role name for the new Role.
49
+ # @param data [hash] Additional Role data.
50
+ def create_role(role_name, data = {})
51
+ raise Auth0::MissingParameter, 'Must supply a valid role_name' if role_name.to_s.empty?
52
+
53
+ data[:name] = role_name
54
+ post roles_path.to_s, data
55
+ end
56
+
57
+ # Update a Role by ID.
58
+ # Required scope: "update:roles"
59
+ # @see https://auth0.com/docs/api/management/v2#!/Roles/patch_roles_by_id
60
+ #
61
+ # @param role_id [string] Role ID to update.
62
+ # @param data [string] Role data to update.
63
+ def update_role(role_id, data = {})
64
+ raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty?
65
+
66
+ patch "#{roles_path}/#{role_id}", data
67
+ end
68
+
69
+ # Delete a single Role by ID.
70
+ # Required scope: "delete:roles"
71
+ # @see https://auth0.com/docs/api/management/v2#!/Roles/delete_roles_by_id
72
+ #
73
+ # @param role_id [string] Role ID to delete.
74
+ def delete_role(role_id)
75
+ raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty?
76
+
77
+ delete "#{roles_path}/#{role_id}"
78
+ end
79
+
80
+ # Get Users assigned to a specific Role.
81
+ # Required scopes:
82
+ # - "read:roles"
83
+ # - "read:users"
84
+ # @see https://auth0.com/docs/api/management/v2#!/Roles/get_role_user
85
+ #
86
+ # @param role_id [string] Role ID to which the Users belong to.
87
+ # @param options [hash] A hash of options for getting Roles
88
+ # - per_page: Number of Roles to return.
89
+ # - page: Page number to return, zero-based.
90
+ # - include_totals: True to include query summary in the result, false or nil otherwise.
91
+ def get_role_users(role_id, options = {})
92
+ raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty?
93
+
94
+ request_params = {
95
+ per_page: options.fetch(:per_page, nil),
96
+ page: options.fetch(:page, nil),
97
+ include_totals: options.fetch(:include_totals, nil)
98
+ }
99
+ get "#{roles_path}/#{role_id}/users", request_params
100
+ end
101
+
102
+ # Add one or more Users to a Role.
103
+ # Required scopes: "update:roles"
104
+ # @see https://auth0.com/docs/api/management/v2#!/Roles/post_role_users
105
+ #
106
+ # @param role_id [string] Role ID to add Users.
107
+ # @param users [array] Array of string User IDs to add to the Role.
108
+ def add_role_users(role_id, users = [])
109
+ raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty?
110
+
111
+ validate_strings_array(users)
112
+ post "#{roles_path}/#{role_id}/users", users: users
113
+ end
114
+
115
+ # Get the permissions associated to a Role.
116
+ # Required scope: "read:roles"
117
+ # @see https://auth0.com/docs/api/management/v2#!/Roles/get_role_permission
118
+ #
119
+ # @param role_id [string] Role ID to add permissions.
120
+ # @param options [hash] A hash of options for getting permissions
121
+ # - per_page: Number or permissions to return.
122
+ # - page: Page number to return, zero-based
123
+ # - include_totals: True to include query summary in the result, false or nil otherwise.
124
+ #
125
+ # @return [json] All permissions matching the query.
126
+ def get_role_permissions(role_id, options = {})
127
+ raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty?
128
+
129
+ request_params = {
130
+ per_page: options.fetch(:per_page, nil),
131
+ page: options.fetch(:page, nil),
132
+ include_totals: options.fetch(:include_totals, nil)
133
+ }
134
+ get "#{roles_path}/#{role_id}/permissions", request_params
135
+ end
136
+
137
+ # Associate permissions with a Role.
138
+ # Required scope: "update:roles"
139
+ # @see https://auth0.com/docs/api/management/v2#!/Roles/post_role_permission_assignment
140
+ #
141
+ # @param role_id [string] Role ID to add permissions.
142
+ # @param permissions [array] Array of Permission structs to add.
143
+ def add_role_permissions(role_id, permissions)
144
+ raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty?
145
+
146
+ permissions = validate_permissions_array(permissions)
147
+ post "#{roles_path}/#{role_id}/permissions", permissions: permissions
148
+ end
149
+
150
+ # Remove permissions from a Role.
151
+ # Required scope: "update:roles"
152
+ # @see https://auth0.com/docs/api/management/v2#!/Roles/delete_role_permission_assignment
153
+ #
154
+ # @param role_id [string] Role ID to remove permissions.
155
+ # @param permissions [array] Array of Permission structs to remove.
156
+ def remove_role_permissions(role_id, permissions)
157
+ raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty?
158
+
159
+ permissions = validate_permissions_array(permissions)
160
+ delete_with_body("#{roles_path}/#{role_id}/permissions", permissions: permissions)
161
+ end
162
+
163
+ private
164
+
165
+ # Roles base API path
166
+ def roles_path
167
+ @roles_path ||= '/api/v2/roles'
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
@@ -3,6 +3,8 @@ module Auth0
3
3
  module V2
4
4
  # Methods to use the users endpoints
5
5
  module Users
6
+ include Auth0::Mixins::Validation
7
+
6
8
  attr_reader :users_path
7
9
 
8
10
  # Retrieves a list of Auth0 users.
@@ -52,7 +54,7 @@ module Auth0
52
54
  end
53
55
 
54
56
  # Delete all users - USE WITH CAUTION
55
- # @see https://auth0.com/docs/api/v2#!/Users/delete_users
57
+ # @deprecated - 4.8.0, endpoint has been removed
56
58
  def delete_users
57
59
  delete(users_path)
58
60
  end
@@ -96,7 +98,7 @@ module Auth0
96
98
  # If your are updating email or phone_number you need to specify the connection and the client_id properties.
97
99
  # @see https://auth0.com/docs/api/v2#!/Users/patch_users_by_id
98
100
  # @param user_id [string] The user_id of the user to update.
99
- # @param body [hash] The optional parametes to update.
101
+ # @param body [hash] The optional parameters to update.
100
102
  #
101
103
  # @return [json] Returns the updated user.
102
104
  def patch_user(user_id, body)
@@ -145,13 +147,14 @@ module Auth0
145
147
  # @param secondary_user_id [string] The unique identifier for the user for the identity.
146
148
  #
147
149
  # @return [json] Returns the array of the unlinked account identities.
148
- def unlink_users_account(user_id, provider, secondary_user_id)
150
+ def unlink_user_account(user_id, provider, secondary_user_id)
149
151
  raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
150
152
  raise Auth0::MissingUserId, 'Must supply a valid secondary user_id' if secondary_user_id.to_s.empty?
151
153
  raise Auth0::InvalidParameter, 'Must supply a valid provider' if provider.to_s.empty?
152
154
  path = "#{users_path}/#{user_id}/identities/#{provider}/#{secondary_user_id}"
153
155
  delete(path)
154
156
  end
157
+ alias unlink_users_account unlink_user_account
155
158
 
156
159
  # Retrieve every log event for a specific user id
157
160
  # @see https://auth0.com/docs/api/management/v2#!/Users/get_logs_by_user
@@ -168,7 +171,6 @@ module Auth0
168
171
  raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
169
172
  path = "#{users_path}/#{user_id}/logs"
170
173
  request_params = {
171
- user_id: user_id,
172
174
  per_page: options.fetch(:per_page, nil),
173
175
  page: options.fetch(:page, nil),
174
176
  include_totals: options.fetch(:include_totals, nil),
@@ -185,12 +187,121 @@ module Auth0
185
187
  end
186
188
  alias get_user_log_events user_logs
187
189
 
190
+ # Get all roles assigned to a specific user.
191
+ # @see https://auth0.com/docs/api/management/v2#!/Users/get_user_roles
192
+ #
193
+ # @param user_id [string] The user_id of the roles to retrieve.
194
+ # @param options [hash]
195
+ # * :per_page [integer] The amount of entries per page. Default: 50. Max value: 100.
196
+ # * :page [integer] The page number. Zero based.
197
+ # * :include_totals [boolean] True if a query summary must be included in the result.
198
+ # * :sort [string] The field to use for sorting. 1 == ascending and -1 == descending.
199
+ #
200
+ # @return [json] Returns roles for the given user_id.
201
+ def get_user_roles(user_id, options = {})
202
+ raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
203
+ path = "#{users_path}/#{user_id}/roles"
204
+ request_params = {
205
+ per_page: options.fetch(:per_page, nil),
206
+ page: options.fetch(:page, nil),
207
+ include_totals: options.fetch(:include_totals, nil)
208
+ }
209
+ get(path, request_params)
210
+ end
211
+
212
+ # Remove one or more roles from a specific user.
213
+ # @see https://auth0.com/docs/api/management/v2#!/Users/delete_user_roles
214
+ #
215
+ # @param user_id [string] The user_id of the roles to remove.
216
+ # @param roles [array] An array of role names to remove.
217
+ def remove_user_roles(user_id, roles)
218
+ raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
219
+ validate_strings_array roles
220
+ path = "#{users_path}/#{user_id}/roles"
221
+ delete_with_body path, roles: roles
222
+ end
223
+
224
+ # Add one or more roles to a specific user.
225
+ # @see https://auth0.com/docs/api/management/v2#!/Users/post_user_roles
226
+ #
227
+ # @param user_id [string] The user_id of the roles to add.
228
+ # @param roles [array] An array of role ids to add.
229
+ def add_user_roles(user_id, roles)
230
+ raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
231
+ validate_strings_array roles
232
+ path = "#{users_path}/#{user_id}/roles"
233
+ post(path, roles: roles)
234
+ end
235
+
236
+ # Get all Guardian enrollments for a specific user
237
+ # @see https://auth0.com/docs/api/management/v2#!/Users/get_enrollments
238
+ #
239
+ # @param user_id [string] The user_id of the enrollments to get.
240
+ #
241
+ # @return [json] Returns Guardian enrollments for the given user_id.
242
+ def get_enrollments(user_id)
243
+ raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
244
+ get "#{users_path}/#{user_id}/enrollments"
245
+ end
246
+
247
+ # Get all permissions for a specific user.
248
+ # @see https://auth0.com/docs/api/management/v2#!/Users/get_permissions
249
+ #
250
+ # @param user_id [string] The user_id of the permissions to get.
251
+ #
252
+ # @return [json] Returns permissions for the given user_id.
253
+ def get_user_permissions(user_id)
254
+ raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
255
+ get "#{users_path}/#{user_id}/permissions"
256
+ end
257
+
258
+ # Remove one or more permissions from a specific user.
259
+ # @see https://auth0.com/docs/api/management/v2#!/Users/delete_permissions
260
+ #
261
+ # @param user_id [string] The user_id of the permissions to remove.
262
+ # @param permissions [array] An array of Permission structs to remove.
263
+ def remove_user_permissions(user_id, permissions)
264
+ raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
265
+ permissions = validate_permissions_array permissions
266
+ delete_with_body "#{users_path}/#{user_id}/permissions", permissions: permissions
267
+ end
268
+
269
+ # Add one or more permissions from a specific user.
270
+ # @see https://auth0.com/docs/api/management/v2#!/Users/post_permissions
271
+ #
272
+ # @param user_id [string] The user_id of the permissions to add.
273
+ # @param permissions [array] An array of Permission structs to add.
274
+ def add_user_permissions(user_id, permissions)
275
+ raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
276
+ permissions = validate_permissions_array permissions
277
+ post "#{users_path}/#{user_id}/permissions", permissions: permissions
278
+ end
279
+
280
+ # Remove the current Guardian recovery code and generates and returns a new one.
281
+ # @see https://auth0.com/docs/api/management/v2#!/Users/post_recovery_code_regeneration
282
+ #
283
+ # @param user_id [string] The user_id of the recovery codes to regenerate.
284
+ def generate_recovery_code(user_id)
285
+ raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
286
+ post "#{users_path}/#{user_id}/recovery-code-generation"
287
+ end
288
+
289
+ # Invalidate all remembered browsers for all authentication factors for a specific user.
290
+ # @see https://auth0.com/docs/api/management/v2#!/Users/post_invalidate_remember_browser
291
+ #
292
+ # @param user_id [string] The user_id of the browsers to invalidate.
293
+ def invalidate_browsers(user_id)
294
+ raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
295
+ post "#{users_path}/#{user_id}/multifactor/actions/invalidate-remember-browser"
296
+ end
297
+
188
298
  private
189
299
 
190
300
  # Users API path
191
301
  def users_path
192
302
  @users_path ||= '/api/v2/users'
193
303
  end
304
+
194
305
  end
195
306
  end
196
307
  end
@@ -2,19 +2,35 @@ module Auth0
2
2
  # Default exception in namespace of Auth0
3
3
  # if you want to catch all exceptions, then you should use this one.
4
4
  # Network exceptions are not included
5
- class Exception < StandardError; end
5
+ class Exception < StandardError
6
+ attr_reader :error_data
7
+ def initialize(message,error_data={})
8
+ super(message)
9
+ @error_data = error_data
10
+ end
11
+ end
12
+ # Parent for all exceptions that arise out of HTTP error responses.
13
+ class HTTPError < Auth0::Exception
14
+ def headers
15
+ error_data[:headers]
16
+ end
17
+
18
+ def http_code
19
+ error_data[:code]
20
+ end
21
+ end
6
22
  # exception for unauthorized requests, if you see it,
7
23
  # probably Bearer Token is not set correctly
8
- class Unauthorized < Auth0::Exception; end
24
+ class Unauthorized < Auth0::HTTPError; end
9
25
  # exception for not found resource, you query for an
10
26
  # unexistent resource, or wrong path
11
- class NotFound < Auth0::Exception; end
27
+ class NotFound < Auth0::HTTPError; end
12
28
  # exception for unknown error
13
- class Unsupported < Auth0::Exception; end
29
+ class Unsupported < Auth0::HTTPError; end
14
30
  # exception for server error
15
- class ServerError < Auth0::Exception; end
31
+ class ServerError < Auth0::HTTPError; end
16
32
  # exception for incorrect request, you've sent wrong params
17
- class BadRequest < Auth0::Exception; end
33
+ class BadRequest < Auth0::HTTPError; end
18
34
  # exception for timeouts
19
35
  class RequestTimeout < Auth0::Exception; end
20
36
  # exception for unset user_id, this might cause removal of
@@ -25,7 +41,7 @@ module Auth0
25
41
  # exception for an unset parameter
26
42
  class MissingParameter < Auth0::Exception; end
27
43
  # Api v2 access denied
28
- class AccessDenied < Auth0::Exception; end
44
+ class AccessDenied < Auth0::HTTPError; end
29
45
  # Invalid parameter passed, e.g. empty where ID is required
30
46
  class InvalidParameter < Auth0::Exception; end
31
47
  # Invalid Auth0 credentials either client_id/secret for API v1
@@ -33,4 +49,16 @@ module Auth0
33
49
  class InvalidCredentials < Auth0::Exception; end
34
50
  # Invalid Auth0 API namespace
35
51
  class InvalidApiNamespace < Auth0::Exception; end
52
+ # Auth0 API rate-limiting encountered
53
+ # TODO: When making API-breaking changes, make this a subclass
54
+ # of Auth0::HTTPError directly rather than Auth0::Unsupported.
55
+ # It's currently under Unsupported to avoid breaking compatibility
56
+ # with prior gem versions that treated 429 errors as unknown errors.
57
+ class RateLimitEncountered < Auth0::Unsupported
58
+ def reset
59
+ Time.at(headers['X-RateLimit-Reset']).utc
60
+ end
61
+ end
62
+
63
+ class InvalidIdToken < Auth0::Exception; end
36
64
  end