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
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Auth0 - Ruby
2
2
 
3
- [![Build Status](https://travis-ci.org/auth0/ruby-auth0.svg?branch=master)](https://travis-ci.org/auth0/ruby-auth0)
3
+ [![CircleCI](https://img.shields.io/circleci/project/github/auth0/ruby-auth0/master.svg)](https://circleci.com/gh/auth0/ruby-auth0)
4
4
  [![Gem Version](https://badge.fury.io/rb/auth0.svg)](http://badge.fury.io/rb/auth0)
5
- [![Coverage Status](https://coveralls.io/repos/auth0/ruby-auth0/badge.svg?branch=master)](https://coveralls.io/r/auth0/ruby-auth0?branch=master)
5
+ [![codecov](https://codecov.io/gh/auth0/ruby-auth0/branch/master/graph/badge.svg)](https://codecov.io/gh/auth0/ruby-auth0)
6
6
  [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://www.rubydoc.info/github/auth0/ruby-auth0/master/frames)
7
7
  [![MIT licensed](https://img.shields.io/dub/l/vibe-d.svg?style=flat)](https://github.com/auth0/ruby-auth0/blob/master/LICENSE)
8
8
 
@@ -12,7 +12,7 @@ Ruby API client for the [Auth0](https://auth0.com) platform.
12
12
 
13
13
  This gem can be installed directly:
14
14
 
15
- ``` bash
15
+ ```bash
16
16
  $ gem install auth0
17
17
  ```
18
18
 
@@ -26,7 +26,7 @@ bundle add auth0
26
26
 
27
27
  You can build the API documentation with the following:
28
28
 
29
- ``` bash
29
+ ```bash
30
30
  bundle exec rake documentation
31
31
  ```
32
32
 
@@ -65,14 +65,23 @@ class AllUsersController < ApplicationController
65
65
  }
66
66
  @users = auth0_client.users @params
67
67
  end
68
-
68
+
69
69
  private
70
-
70
+
71
71
  # Setup the Auth0 API connection.
72
72
  def auth0_client
73
73
  @auth0_client ||= Auth0Client.new(
74
74
  client_id: ENV['AUTH0_RUBY_CLIENT_ID'],
75
- token: ENV['AUTH0_RUBY_API_TOKEN'],
75
+ client_secret: ENV['AUTH0_RUBY_CLIENT_SECRET'],
76
+ # If you pass in a client_secret value, the SDK will automatically try to get a
77
+ # Management API token for this application. Make sure your Application can make a
78
+ # Client Credentials grant (Application settings in Auth0 > Advanced > Grant Types
79
+ # tab) and that the Application is authorized for the Management API:
80
+ # https://auth0.com/docs/api-auth/config/using-the-auth0-dashboard
81
+ #
82
+ # Otherwise, you can pass in a Management API token directly for testing or temporary
83
+ # access using the key below.
84
+ # token: ENV['AUTH0_RUBY_API_TOKEN'],
76
85
  domain: ENV['AUTH0_RUBY_DOMAIN'],
77
86
  api_version: 2,
78
87
  timeout: 15 # optional, defaults to 10
@@ -98,36 +107,116 @@ This should show the parameters passed to the `users` method and a list of users
98
107
 
99
108
  In addition to the Management API, this SDK also provides access to [Authentication API](https://auth0.com/docs/api/authentication) endpoints with the `Auth0::API::AuthenticationEndpoints` module. For basic login capability, we suggest using our OmniAuth stategy [detailed here](https://auth0.com/docs/quickstart/webapp/rails/01-login). Other authentication tasks currently supported are:
100
109
 
101
- * Register a new user with a database connection using the `signup` method.
102
- * Redirect a user to the universal login page for authentication using the `authorization_url` method.
103
- * Log a user into a highly trusted app with the [Resource Owner Password grant](https://auth0.com/docs/api-auth/tutorials/password-grant) using the `login` method.
104
- * Exchange an authorization code for an access token on callback using the `obtain_user_tokens` method (see the note on state validation below).
105
- * Send a change password email to a database connection user using the `change_password` method.
106
- * Log a user out of Auth0 with the `logout_url` method.
110
+ - Register a new user with a database connection using the `signup` method.
111
+ - Redirect a user to the universal login page for authentication using the `authorization_url` method.
112
+ - Log a user into a highly trusted app with the [Resource Owner Password grant](https://auth0.com/docs/api-auth/tutorials/password-grant) using the `login` method.
113
+ - Exchange an authorization code for an access token on callback using the `obtain_user_tokens` method (see the note on state validation below).
114
+ - Send a change password email to a database connection user using the `change_password` method.
115
+ - Log a user out of Auth0 with the `logout_url` method.
107
116
 
108
- **Important note on state validation**: If you choose to implement a login flow callback yourself, it is important to generate and store a `state` value, pass that value to Auth0 in the `authorization_url` method, and validate it in your callback URL before calling `obtain_user_tokens`. For more information on state validation, [please see our documentation](https://auth0.com/docs/protocols/oauth2/oauth-state).
117
+ **Important note on state validation**: If you choose to implement a login flow callback yourself, it is important to generate and store a `state` value, pass that value to Auth0 in the `authorization_url` method, and validate it in your callback URL before calling `obtain_user_tokens`. For more information on state validation, [please see our documentation](https://auth0.com/docs/protocols/oauth2/oauth-state).
109
118
 
110
119
  Please note that this module implements endpoints that might be deprecated for newer tenants. If you have any questions about how and when the endpoints should be used, consult the [documentation](https://auth0.com/docs/api/authentication) or ask in our [Community forums](https://community.auth0.com/tags/wordpress).
111
120
 
121
+ ## ID Token Validation
122
+
123
+ An ID token may be present in the credentials received after authentication. This token contains information associated with the user that has just logged in, provided the scope used contained `openid`. You can [read more about ID tokens here](https://auth0.com/docs/tokens/concepts/id-tokens).
124
+
125
+ Before accessing its contents, you must first validate the ID token to ensure it has not been tampered with and that it is meant for your application to consume. Use the `validate_id_token` method to do so:
126
+
127
+ ```ruby
128
+ begin
129
+ @auth0_client.validate_id_token 'YOUR_ID_TOKEN'
130
+ rescue Auth0::InvalidIdToken => e
131
+ # In this case the ID Token contents should not be trusted
132
+ end
133
+ ```
134
+
135
+ The method takes the following optional keyword parameters:
136
+
137
+ | Parameter | Type | Description | Default value |
138
+ | ------------- | -------------- | ------------- | ------------------------- |
139
+ | `algorithm` | `JWTAlgorithm` | The [signing algorithm](https://auth0.com/docs/tokens/concepts/signing-algorithms) used by your Auth0 application. | `Auth0::Algorithm::RS256` (using the [JWKS URL](https://auth0.com/docs/tokens/concepts/jwks) of your **Auth0 Domain**) |
140
+ | `leeway` | Integer | Number of seconds to account for clock skew when validating the `exp`, `iat` and `azp` claims. | `60` |
141
+ | `nonce` | String | The `nonce` value you sent in the call to `/authorize`, if any. | `nil` |
142
+ | `max_age` | Integer | The `max_age` value you sent in the call to `/authorize`, if any. | `nil` |
143
+ | `issuer` | String | By default the `iss` claim will be checked against the URL of your **Auth0 Domain**. Use this parameter to override that. | `nil` |
144
+ | `audience` | String | By default the `aud` claim will be compared to your **Auth0 Client ID**. Use this parameter to override that. | `nil` |
145
+
146
+ You can check the signing algorithm value under **Advanced Settings > OAuth > JsonWebToken Signature Algorithm** in your Auth0 application settings panel. [We recommend](https://auth0.com/docs/tokens/concepts/signing-algorithms#our-recommendation) that you make use of asymmetric signing algorithms like `RS256` instead of symmetric ones like `HS256`.
147
+
148
+ ```ruby
149
+ # HS256
150
+
151
+ begin
152
+ @auth0_client.validate_id_token 'YOUR_ID_TOKEN', algorithm: Auth0::Algorithm::HS256.secret('YOUR_SECRET')
153
+ rescue Auth0::InvalidIdToken => e
154
+ # Handle error
155
+ end
156
+
157
+ # RS256 with a custom JWKS URL
158
+
159
+ begin
160
+ @auth0_client.validate_id_token 'YOUR_ID_TOKEN', algorithm: Auth0::Algorithm::RS256.jwks_url('YOUR_URL')
161
+ rescue Auth0::InvalidIdToken => e
162
+ # Handle error
163
+ end
164
+ ```
165
+
166
+ ## Development
167
+
168
+ In order to set up the local environment you'd have to have Ruby installed and a few global gems used to run and record the unit tests. A working Ruby version can be taken from the [CI script](/.circleci/config.yml). At the moment of this writting we're using Ruby `2.5.7`.
169
+
170
+ > It is expected that every Pull Request introducing a fix, change or feature contains enough test coverage to assert the new behavior.
171
+
172
+ ### Running the tests
173
+
174
+ Install the gems required for this project.
175
+
176
+ ```bash
177
+ bundle install
178
+ ```
179
+
180
+ Finally, run the tests.
181
+
182
+ ```bash
183
+ bundle exec rake test
184
+ ```
185
+
186
+ #### Running only unit tests
187
+
188
+ You can run only the unit tests and ignore the integration tests by running the following:
189
+
190
+ ```bash
191
+ bundle exec rake spec
192
+ ```
193
+
194
+ #### Running only integration tests
195
+
196
+ You can run only the unit tests and ignore the integration tests by running the following:
197
+
198
+ ```bash
199
+ bundle exec rake integration
200
+ ```
112
201
 
113
202
  ## More Information
114
203
 
115
- * [Login using OmniAuth](https://auth0.com/docs/quickstart/webapp/rails/01-login)
116
- * [API authentication in Ruby](https://auth0.com/docs/quickstart/backend/ruby)
117
- * [API authentication in Rails](https://auth0.com/docs/quickstart/backend/rails)
118
- * [Managing authentication with Auth0 (blog)](https://auth0.com/blog/rails-5-with-auth0/)
119
- * [Ruby on Rails workflow with Docker (blog)](https://auth0.com/blog/ruby-on-rails-killer-workflow-with-docker-part-1/)
204
+ - [Login using OmniAuth](https://auth0.com/docs/quickstart/webapp/rails/01-login)
205
+ - [API authentication in Ruby](https://auth0.com/docs/quickstart/backend/ruby)
206
+ - [API authentication in Rails](https://auth0.com/docs/quickstart/backend/rails)
207
+ - [Managing authentication with Auth0 (blog)](https://auth0.com/blog/rails-5-with-auth0/)
208
+ - [Ruby on Rails workflow with Docker (blog)](https://auth0.com/blog/ruby-on-rails-killer-workflow-with-docker-part-1/)
120
209
 
121
210
  ## What is Auth0?
122
211
 
123
212
  Auth0 helps you to:
124
213
 
125
- * Add authentication with [multiple authentication sources](https://docs.auth0.com/identityproviders), either social like **Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce** among others, or enterprise identity systems like **Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider**.
126
- * Add authentication through more traditional **[username/password databases](https://docs.auth0.com/mysql-connection-tutorial)**.
127
- * Add support for **[linking different user accounts](https://docs.auth0.com/link-accounts)** with the same user.
128
- * Support for generating signed [JSON Web Tokens](https://docs.auth0.com/jwt) to call your APIs and **flow the user identity** securely.
129
- * Analytics of how, when, and where users are logging in.
130
- * Pull data from other sources and add it to the user profile with [JavaScript rules](https://docs.auth0.com/rules).
214
+ - Add authentication with [multiple authentication sources](https://docs.auth0.com/identityproviders), either social like **Google, Facebook, Microsoft Account, LinkedIn, GitHub, Twitter, Box, Salesforce** among others, or enterprise identity systems like **Windows Azure AD, Google Apps, Active Directory, ADFS or any SAML Identity Provider**.
215
+ - Add authentication through more traditional **[username/password databases](https://docs.auth0.com/mysql-connection-tutorial)**.
216
+ - Add support for **[linking different user accounts](https://docs.auth0.com/link-accounts)** with the same user.
217
+ - Support for generating signed [JSON Web Tokens](https://docs.auth0.com/jwt) to call your APIs and **flow the user identity** securely.
218
+ - Analytics of how, when, and where users are logging in.
219
+ - Pull data from other sources and add it to the user profile with [JavaScript rules](https://docs.auth0.com/rules).
131
220
 
132
221
  ## Create a free Auth0 Account
133
222
 
@@ -11,24 +11,24 @@ Gem::Specification.new do |s|
11
11
  s.summary = 'Auth0 API Client'
12
12
  s.description = 'Ruby toolkit for Auth0 API https://auth0.com.'
13
13
 
14
- s.rubyforge_project = 'auth0'
15
-
16
14
  s.files = `git ls-files`.split("\n")
17
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
16
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
17
  s.require_paths = ['lib']
20
18
 
21
- s.add_runtime_dependency 'rest-client', '~> 2.0'
19
+ s.add_runtime_dependency 'rest-client', '~> 2.0.0'
20
+ s.add_runtime_dependency 'jwt', '~> 2.2.0'
21
+ s.add_runtime_dependency 'zache', '~> 0.12.0'
22
22
 
23
- s.add_development_dependency 'rake', '~> 10.4'
23
+ s.add_development_dependency 'rake', '~> 13.0'
24
24
  s.add_development_dependency 'fuubar', '~> 2.0'
25
- s.add_development_dependency 'guard-rspec', '~> 4.5' unless ENV['TRAVIS']
25
+ s.add_development_dependency 'guard-rspec', '~> 4.5' unless ENV['CIRCLECI']
26
26
  s.add_development_dependency 'dotenv-rails', '~> 2.0'
27
27
  s.add_development_dependency 'pry', '~> 0.10'
28
28
  s.add_development_dependency 'pry-nav', '~> 0.2.4'
29
29
  s.add_development_dependency 'rspec', '~> 3.1', '>= 3.1.0'
30
30
  s.add_development_dependency 'rack-test', '~> 0.6'
31
- s.add_development_dependency 'rack', '~> 1.6.4'
31
+ s.add_development_dependency 'rack', '~> 2.1.2'
32
32
  s.add_development_dependency 'simplecov', '~> 0.9'
33
33
  s.add_development_dependency 'faker', '~> 1.4'
34
34
  s.add_development_dependency 'yard', '~> 0.9.12'
@@ -0,0 +1,22 @@
1
+ coverage:
2
+ precision: 2
3
+ round: down
4
+ range: "60...100"
5
+ status:
6
+ project:
7
+ default:
8
+ enabled: true
9
+ target: auto
10
+ threshold: 5%
11
+ if_no_uploads: error
12
+ patch:
13
+ default:
14
+ enabled: true
15
+ target: 80%
16
+ threshold: 30%
17
+ if_no_uploads: error
18
+ changes:
19
+ default:
20
+ enabled: true
21
+ if_no_uploads: error
22
+ comment: false
@@ -14,7 +14,7 @@ cd doc
14
14
  git init
15
15
 
16
16
  # inside this git repo we'll pretend to be a new user
17
- git config user.name "Travis CI"
17
+ git config user.name "Circle CI"
18
18
  git config user.email "build-documentation@auth0.com"
19
19
 
20
20
  # The first and only commit to this new Git repo contains all the
@@ -1,6 +1,7 @@
1
1
  require 'auth0/version'
2
2
  require 'auth0/mixins'
3
3
  require 'auth0/exception'
4
+ require 'auth0/algorithm'
4
5
  require 'auth0/client'
5
6
  require 'auth0_client'
6
7
  # Namespace for ruby-auth0 logic
@@ -0,0 +1,5 @@
1
+ module Auth0
2
+ module Algorithm
3
+ include Auth0::Mixins::Validation::Algorithm
4
+ end
5
+ end
@@ -1,4 +1,8 @@
1
+ # frozen_string_literal: true
1
2
  # rubocop:disable Metrics/ModuleLength
3
+
4
+ require 'jwt'
5
+
2
6
  module Auth0
3
7
  module Api
4
8
  # {https://auth0.com/docs/api/authentication}
@@ -170,7 +174,8 @@ module Auth0
170
174
  send: send,
171
175
  authParams: auth_params,
172
176
  connection: 'email',
173
- client_id: @client_id
177
+ client_id: @client_id,
178
+ client_secret: @client_secret
174
179
  }
175
180
  post('/passwordless/start', request_params)
176
181
  end
@@ -185,7 +190,8 @@ module Auth0
185
190
  request_params = {
186
191
  phone_number: phone_number,
187
192
  connection: 'sms',
188
- client_id: @client_id
193
+ client_id: @client_id,
194
+ client_secret: @client_secret
189
195
  }
190
196
  post('/passwordless/start', request_params)
191
197
  end
@@ -500,6 +506,36 @@ module Auth0
500
506
  post('/unlink', request_params)
501
507
  end
502
508
 
509
+ # Validate an ID token (signature and expiration).
510
+ # @see https://auth0.com/docs/tokens/guides/validate-id-tokens
511
+ # @param id_token [string] The JWT to validate.
512
+ # @param algorithm [JWKAlgorithm] The expected signing algorithm.
513
+ # Defaults to +Auth0::Algorithm::RS256.jwks_url("https://YOUR_AUTH0_DOMAIN/.well-known/jwks.json", lifetime: 10 * 60)+.
514
+ # @param leeway [integer] The clock skew to accept when verifying date related claims in seconds.
515
+ # Must be a non-negative value. Defaults to *60 seconds*.
516
+ # @param nonce [string] The nonce value sent during authentication.
517
+ # @param max_age [integer] The max_age value sent during authentication.
518
+ # Must be a non-negative value.
519
+ # @param issuer [string] The expected issuer claim value.
520
+ # Defaults to +https://YOUR_AUTH0_DOMAIN/+.
521
+ # @param audience [string] The expected audience claim value.
522
+ # Defaults to your *Auth0 Client ID*.
523
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/ParameterLists
524
+ def validate_id_token(id_token, algorithm: nil, leeway: 60, nonce: nil, max_age: nil, issuer: nil, audience: nil)
525
+ context = {
526
+ issuer: issuer || "https://#{@domain}/",
527
+ audience: audience || @client_id,
528
+ algorithm: algorithm || Auth0::Algorithm::RS256.jwks_url("https://#{@domain}/.well-known/jwks.json"),
529
+ leeway: leeway
530
+ }
531
+
532
+ context[:nonce] = nonce unless nonce.nil?
533
+ context[:max_age] = max_age unless max_age.nil?
534
+
535
+ Auth0::Mixins::Validation::IdTokenValidator.new(context).validate(id_token)
536
+ end
537
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/ParameterLists
538
+
503
539
  private
504
540
 
505
541
  # Build a URL query string from a hash.
@@ -1,3 +1,4 @@
1
+ require 'auth0/api/v2/anomaly'
1
2
  require 'auth0/api/v2/blacklists'
2
3
  require 'auth0/api/v2/clients'
3
4
  require 'auth0/api/v2/client_grants'
@@ -6,6 +7,7 @@ require 'auth0/api/v2/device_credentials'
6
7
  require 'auth0/api/v2/emails'
7
8
  require 'auth0/api/v2/jobs'
8
9
  require 'auth0/api/v2/rules'
10
+ require 'auth0/api/v2/roles'
9
11
  require 'auth0/api/v2/stats'
10
12
  require 'auth0/api/v2/users'
11
13
  require 'auth0/api/v2/users_by_email'
@@ -14,11 +16,13 @@ require 'auth0/api/v2/tenants'
14
16
  require 'auth0/api/v2/tickets'
15
17
  require 'auth0/api/v2/logs'
16
18
  require 'auth0/api/v2/resource_servers'
19
+ require 'auth0/api/v2/guardian'
17
20
 
18
21
  module Auth0
19
22
  module Api
20
23
  # https://auth0.com/docs/apiv2
21
24
  module V2
25
+ include Auth0::Api::V2::Anomaly
22
26
  include Auth0::Api::V2::Blacklists
23
27
  include Auth0::Api::V2::Clients
24
28
  include Auth0::Api::V2::ClientGrants
@@ -27,6 +31,7 @@ module Auth0
27
31
  include Auth0::Api::V2::Emails
28
32
  include Auth0::Api::V2::Jobs
29
33
  include Auth0::Api::V2::Rules
34
+ include Auth0::Api::V2::Roles
30
35
  include Auth0::Api::V2::Stats
31
36
  include Auth0::Api::V2::Users
32
37
  include Auth0::Api::V2::UsersByEmail
@@ -35,6 +40,7 @@ module Auth0
35
40
  include Auth0::Api::V2::Tickets
36
41
  include Auth0::Api::V2::Logs
37
42
  include Auth0::Api::V2::ResourceServers
43
+ include Auth0::Api::V2::Guardian
38
44
  end
39
45
  end
40
46
  end
@@ -0,0 +1,36 @@
1
+ module Auth0
2
+ module Api
3
+ module V2
4
+ # Methods to use the anomaly endpoints
5
+ module Anomaly
6
+ # Use this route to determine if a given IP is currently blocked
7
+ # by the failed login to multiple user accounts trigger.
8
+ # @see https://auth0.com/docs/api/management/v2#!/Anomaly/get_ips_by_id
9
+ # @param ip [string] The IP to check.
10
+ def check_if_ip_is_blocked(ip)
11
+ raise Auth0::InvalidParameter, 'Must specify an IP' if ip.to_s.empty?
12
+
13
+ path = "#{anomaly_path}/#{ip}"
14
+ get(path)
15
+ end
16
+
17
+ # Resets an IP that is currently blocked by the failed login to multiple user accounts trigger.
18
+ # @see https://auth0.com/docs/api/management/v2#!/Anomaly/delete_ips_by_id
19
+ # @param ip [string] The IP to remove block.
20
+ def remove_ip_block(ip)
21
+ raise Auth0::InvalidParameter, 'Must specify an IP' if ip.to_s.empty?
22
+
23
+ path = "#{anomaly_path}/#{ip}"
24
+ delete(path)
25
+ end
26
+
27
+ private
28
+
29
+ # Anomaly API path
30
+ def anomaly_path
31
+ @anomaly_path ||= '/api/v2/anomaly/blocks/ips'
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -7,11 +7,15 @@ module Auth0
7
7
 
8
8
  # Retrieves a list of all client grants.
9
9
  # @see https://auth0.com/docs/api/management/v2#!/client_grants/get_client_grants
10
+ # @param client_id [string] The client_id of the client grant to retrieve.
11
+ # @param audience [string] The audience of the client grant to retrieve.
10
12
  # @param page [int] Page number to get, 0-based.
11
13
  # @param per_page [int] Results per page if also passing a page number.
12
14
  # @return [json] Returns the client grants.
13
- def client_grants (page: nil, per_page: nil)
15
+ def client_grants (client_id: nil, audience: nil, page: nil, per_page: nil)
14
16
  request_params = {
17
+ client_id: client_id,
18
+ audience: audience,
15
19
  page: page,
16
20
  per_page: per_page
17
21
  }
@@ -0,0 +1,142 @@
1
+ module Auth0
2
+ module Api
3
+ module V2
4
+ # Methods to use the guardian endpoints
5
+ module Guardian
6
+ include Auth0::Mixins::Validation
7
+
8
+ # Retrieves a list of Guardian factors.
9
+ # @see https://auth0.com/docs/api/management/v2#!/Guardian/get_factors
10
+ # @return [json] Returns the list of all Guardian factors.
11
+ def guardian_factors
12
+ get(guardian_factors_path)
13
+ end
14
+ alias get_guardian_factors guardian_factors
15
+
16
+ # Retrieves a single Guardian enrollment.
17
+ # @see https://auth0.com/docs/api/management/v2#!/Guardian/get_enrollments_by_id
18
+ # @param enrollment_id [string] The enrollment_id of the Guardian enrollment to delete.
19
+ # @return [json] Returns details of the Guardian enrollment.
20
+ def guardian_enrollment(enrollment_id)
21
+ raise Auth0::MissingParameter, 'Must supply a valid enrollment_id' if enrollment_id.to_s.empty?
22
+
23
+ path = "#{guardian_enrollments_path}/#{enrollment_id}"
24
+ get(path)
25
+ end
26
+ alias get_guardian_enrollment guardian_enrollment
27
+
28
+ # Deletes a single Guardian enrollment given its id.
29
+ # @see https://auth0.com/docs/api/management/v2#!/Guardian/delete_enrollments_by_id
30
+ # @param enrollment_id [string] The enrollment_id of the Guardian enrollment to delete.
31
+ def delete_guardian_enrollment(enrollment_id)
32
+ raise Auth0::MissingParameter, 'Must supply a valid enrollment_id' if enrollment_id.to_s.empty?
33
+
34
+ path = "#{guardian_enrollments_path}/#{enrollment_id}"
35
+ delete(path)
36
+ end
37
+
38
+ # Retrieves SMS enrollment and verification templates.
39
+ # @see https://auth0.com/docs/api/management/v2#!/Guardian/get_templates
40
+ # @return [json] Returns enrollment and verification templates.
41
+ def guardian_sms_templates
42
+ path = "#{guardian_factors_path}/sms/templates"
43
+ get(path)
44
+ end
45
+ alias get_guardian_sms_templates guardian_sms_templates
46
+
47
+ # Updates SMS enrollment and verification SMS templates.
48
+ # @see https://auth0.com/docs/api/management/v2#!/Guardian/put_templates
49
+ # @param body [hash] The parameters to update.
50
+ #
51
+ # @return [json] Returns updated SMS enrollment and verification templates.
52
+ def guardian_update_enrollment_verification_templates(body)
53
+ raise Auth0::InvalidParameter, 'Must supply a valid body' if body.to_s.empty?
54
+
55
+ path = "#{guardian_factors_path}/sms/templates"
56
+ put(path, body)
57
+ end
58
+
59
+ # Retrieves provider configuration for AWS SNS.
60
+ # @see https://auth0.com/docs/api/management/v2#!/Guardian/get_sns
61
+ # @return [json] Returns provider configuration for AWS SNS.
62
+ def guardian_sns_provider_config
63
+ path = "#{guardian_factors_path}/push-notification/providers/sns"
64
+ get(path)
65
+ end
66
+ alias get_guardian_sns_provider_config guardian_sns_provider_config
67
+
68
+ # Updates provider configuration for AWS SNS.
69
+ # @see https://auth0.com/docs/api/management/v2#!/Guardian/put_sns
70
+ # @param body [hash] The parameters to update.
71
+ #
72
+ # @return [json] Returns updated provider configuration for AWS SNS.
73
+ def guardian_update_sns_provider_config(body)
74
+ raise Auth0::InvalidParameter, 'Must supply a valid body' if body.to_s.empty?
75
+
76
+ path = "#{guardian_factors_path}/push-notification/providers/sns"
77
+ put(path, body)
78
+ end
79
+
80
+ # Retrieves provider configuration for Twilio.
81
+ # @see https://auth0.com/docs/api/management/v2#!/Guardian/get_twilio
82
+ # @return [json] Returns provider configuration for Twilio.
83
+ def guardian_twillo_provider_config
84
+ path = "#{guardian_factors_path}/sms/providers/twilio"
85
+ get(path)
86
+ end
87
+ alias get_guardian_twillo_provider_config guardian_twillo_provider_config
88
+
89
+ # Updates provider configuration for Twilio.
90
+ # @see https://auth0.com/docs/api/management/v2#!/Guardian/put_twilio
91
+ # @param body [hash] The parameters to update.
92
+ #
93
+ # @return [json] Returns updated provider configuration for Twilio.
94
+ def guardian_update_twillo_provider_config(body)
95
+ raise Auth0::InvalidParameter, 'Must supply a valid body' if body.to_s.empty?
96
+
97
+ path = "#{guardian_factors_path}/sms/providers/twilio"
98
+ put(path, body)
99
+ end
100
+
101
+ # Creates a Guardian enrollment ticket.
102
+ # @see https://auth0.com/docs/api/management/v2#!/Guardian/post_ticket
103
+ # @param body [hash] User details to create enrollment ticket for.
104
+ # @return [json] Returns details of created enrollment ticket.
105
+ def guardian_create_enrollment_ticket(body)
106
+ raise Auth0::InvalidParameter, 'Must supply a valid body' if body.to_s.empty?
107
+
108
+ path = "#{guardian_enrollments_path}/ticket"
109
+ post(path, body)
110
+ end
111
+
112
+ # Updates a Guardian factor.
113
+ # @see https://auth0.com/docs/api/management/v2#!/Guardian/put_factors_by_name
114
+ # @param name [string] Name of Guardian factor to update.
115
+ # @param body [hash] The parameters to update.
116
+ # @return [json] Returns details of updated Guardian factor.
117
+ def guardian_update_factor(name, body)
118
+ raise Auth0::MissingParameter, 'Must supply a valid name' if name.to_s.empty?
119
+ raise Auth0::InvalidParameter, 'Must supply a valid body' if body.to_s.empty?
120
+
121
+ path = "#{guardian_factors_path}/#{name}"
122
+ put(path, body)
123
+ end
124
+
125
+ private
126
+
127
+ # Guardian API path
128
+ def guardian_path
129
+ @guardian_path ||= '/api/v2/guardian'
130
+ end
131
+
132
+ def guardian_enrollments_path
133
+ @guardian_enrollments_path ||= "#{guardian_path}/enrollments"
134
+ end
135
+
136
+ def guardian_factors_path
137
+ @guardian_factors_path ||= "#{guardian_path}/factors"
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end