auth0 4.11.0 → 5.20.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 (358) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -0
  3. data/CHANGELOG.md +477 -19
  4. data/README.md +80 -129
  5. data/auth0.gemspec +10 -13
  6. data/lib/auth0/algorithm.rb +5 -0
  7. data/lib/auth0/api/authentication_endpoints.rb +189 -242
  8. data/lib/auth0/api/v2/actions.rb +209 -0
  9. data/lib/auth0/api/v2/attack_protection.rb +79 -0
  10. data/lib/auth0/api/v2/branding.rb +65 -0
  11. data/lib/auth0/api/v2/client_grants.rb +27 -2
  12. data/lib/auth0/api/v2/clients.rb +42 -0
  13. data/lib/auth0/api/v2/connections.rb +14 -5
  14. data/lib/auth0/api/v2/device_credentials.rb +12 -7
  15. data/lib/auth0/api/v2/grants.rb +49 -0
  16. data/lib/auth0/api/v2/jobs.rb +28 -5
  17. data/lib/auth0/api/v2/log_streams.rb +78 -0
  18. data/lib/auth0/api/v2/logs.rb +2 -2
  19. data/lib/auth0/api/v2/organizations.rb +407 -0
  20. data/lib/auth0/api/v2/prompts.rb +70 -0
  21. data/lib/auth0/api/v2/refresh_tokens.rb +34 -0
  22. data/lib/auth0/api/v2/roles.rb +7 -3
  23. data/lib/auth0/api/v2/sessions.rb +43 -0
  24. data/lib/auth0/api/v2/tickets.rb +25 -2
  25. data/lib/auth0/api/v2/users.rb +216 -14
  26. data/lib/auth0/api/v2.rb +21 -3
  27. data/lib/auth0/client_assertion.rb +45 -0
  28. data/lib/auth0/exception.rb +19 -8
  29. data/lib/auth0/mixins/access_token_struct.rb +2 -2
  30. data/lib/auth0/mixins/api_token_struct.rb +2 -3
  31. data/lib/auth0/mixins/httpproxy.rb +99 -35
  32. data/lib/auth0/mixins/initializer.rb +6 -9
  33. data/lib/auth0/mixins/permission_struct.rb +2 -2
  34. data/lib/auth0/mixins/token_management.rb +35 -0
  35. data/lib/auth0/mixins/validation.rb +335 -1
  36. data/lib/auth0/mixins.rb +2 -1
  37. data/lib/auth0/version.rb +1 -1
  38. data/lib/auth0.rb +1 -0
  39. metadata +71 -608
  40. data/.bundle/config +0 -4
  41. data/.circleci/config.yml +0 -23
  42. data/.env.example +0 -2
  43. data/.gemrelease +0 -2
  44. data/.github/CODEOWNERS +0 -1
  45. data/.github/ISSUE_TEMPLATE.md +0 -39
  46. data/.github/PULL_REQUEST_TEMPLATE.md +0 -35
  47. data/.github/stale.yml +0 -20
  48. data/.gitignore +0 -14
  49. data/.rspec +0 -3
  50. data/.rubocop.yml +0 -10
  51. data/.rubocop_todo.yml +0 -5
  52. data/CODE_OF_CONDUCT.md +0 -3
  53. data/DEPLOYMENT.md +0 -61
  54. data/Dockerfile +0 -5
  55. data/Gemfile +0 -19
  56. data/Gemfile.lock +0 -224
  57. data/Guardfile +0 -37
  58. data/RUBYGEM.md +0 -9
  59. data/Rakefile +0 -53
  60. data/codecov.yml +0 -22
  61. data/deploy_documentation.sh +0 -29
  62. data/doc_config/templates/default/fulldoc/html/css/full_list.css +0 -79
  63. data/doc_config/templates/default/fulldoc/html/css/style.css +0 -546
  64. data/doc_config/templates/default/layout/html/breadcrumb.erb +0 -11
  65. data/doc_config/templates/default/layout/html/footer.erb +0 -115
  66. data/doc_config/templates/default/layout/html/headers.erb +0 -17
  67. data/doc_config/templates/default/layout/html/layout.erb +0 -27
  68. data/examples/ruby-api/.env.example +0 -2
  69. data/examples/ruby-api/.gitignore +0 -86
  70. data/examples/ruby-api/Gemfile +0 -8
  71. data/examples/ruby-api/README.md +0 -24
  72. data/examples/ruby-api/config.ru +0 -2
  73. data/examples/ruby-api/main.rb +0 -33
  74. data/examples/ruby-on-rails-api/.env.example +0 -2
  75. data/examples/ruby-on-rails-api/.gitignore +0 -18
  76. data/examples/ruby-on-rails-api/Gemfile +0 -48
  77. data/examples/ruby-on-rails-api/README.md +0 -27
  78. data/examples/ruby-on-rails-api/Rakefile +0 -6
  79. data/examples/ruby-on-rails-api/app/assets/images/.keep +0 -0
  80. data/examples/ruby-on-rails-api/app/assets/javascripts/application.js +0 -16
  81. data/examples/ruby-on-rails-api/app/assets/stylesheets/application.css +0 -15
  82. data/examples/ruby-on-rails-api/app/controllers/application_controller.rb +0 -8
  83. data/examples/ruby-on-rails-api/app/controllers/concerns/.keep +0 -0
  84. data/examples/ruby-on-rails-api/app/controllers/ping_controller.rb +0 -6
  85. data/examples/ruby-on-rails-api/app/controllers/secured_ping_controller.rb +0 -11
  86. data/examples/ruby-on-rails-api/app/helpers/application_helper.rb +0 -3
  87. data/examples/ruby-on-rails-api/app/mailers/.keep +0 -0
  88. data/examples/ruby-on-rails-api/app/models/.keep +0 -0
  89. data/examples/ruby-on-rails-api/app/models/User.rb +0 -5
  90. data/examples/ruby-on-rails-api/app/models/concerns/.keep +0 -0
  91. data/examples/ruby-on-rails-api/app/views/layouts/application.html.erb +0 -14
  92. data/examples/ruby-on-rails-api/bin/bundle +0 -3
  93. data/examples/ruby-on-rails-api/bin/rails +0 -4
  94. data/examples/ruby-on-rails-api/bin/rake +0 -4
  95. data/examples/ruby-on-rails-api/bin/setup +0 -29
  96. data/examples/ruby-on-rails-api/config/application.rb +0 -23
  97. data/examples/ruby-on-rails-api/config/boot.rb +0 -4
  98. data/examples/ruby-on-rails-api/config/database.yml +0 -27
  99. data/examples/ruby-on-rails-api/config/environment.rb +0 -5
  100. data/examples/ruby-on-rails-api/config/environments/development.rb +0 -37
  101. data/examples/ruby-on-rails-api/config/environments/production.rb +0 -83
  102. data/examples/ruby-on-rails-api/config/environments/test.rb +0 -41
  103. data/examples/ruby-on-rails-api/config/initializers/backtrace_silencers.rb +0 -7
  104. data/examples/ruby-on-rails-api/config/initializers/cookies_serializer.rb +0 -3
  105. data/examples/ruby-on-rails-api/config/initializers/dotenv.rb +0 -4
  106. data/examples/ruby-on-rails-api/config/initializers/filter_parameter_logging.rb +0 -4
  107. data/examples/ruby-on-rails-api/config/initializers/inflections.rb +0 -16
  108. data/examples/ruby-on-rails-api/config/initializers/knock.rb +0 -35
  109. data/examples/ruby-on-rails-api/config/initializers/mime_types.rb +0 -4
  110. data/examples/ruby-on-rails-api/config/initializers/session_store.rb +0 -3
  111. data/examples/ruby-on-rails-api/config/initializers/wrap_parameters.rb +0 -14
  112. data/examples/ruby-on-rails-api/config/locales/en.yml +0 -23
  113. data/examples/ruby-on-rails-api/config/routes.rb +0 -58
  114. data/examples/ruby-on-rails-api/config/secrets.yml +0 -28
  115. data/examples/ruby-on-rails-api/config.ru +0 -4
  116. data/examples/ruby-on-rails-api/db/schema.rb +0 -15
  117. data/examples/ruby-on-rails-api/db/seeds.rb +0 -7
  118. data/examples/ruby-on-rails-api/lib/assets/.keep +0 -0
  119. data/examples/ruby-on-rails-api/lib/tasks/.keep +0 -0
  120. data/examples/ruby-on-rails-api/log/.keep +0 -0
  121. data/examples/ruby-on-rails-api/public/404.html +0 -67
  122. data/examples/ruby-on-rails-api/public/422.html +0 -67
  123. data/examples/ruby-on-rails-api/public/500.html +0 -66
  124. data/examples/ruby-on-rails-api/public/favicon.ico +0 -0
  125. data/examples/ruby-on-rails-api/public/robots.txt +0 -5
  126. data/examples/ruby-on-rails-api/test/controllers/.keep +0 -0
  127. data/examples/ruby-on-rails-api/test/fixtures/.keep +0 -0
  128. data/examples/ruby-on-rails-api/test/helpers/.keep +0 -0
  129. data/examples/ruby-on-rails-api/test/integration/.keep +0 -0
  130. data/examples/ruby-on-rails-api/test/mailers/.keep +0 -0
  131. data/examples/ruby-on-rails-api/test/models/.keep +0 -0
  132. data/examples/ruby-on-rails-api/test/ping_controller_test.rb +0 -8
  133. data/examples/ruby-on-rails-api/test/secured_ping_controller_test.rb +0 -26
  134. data/examples/ruby-on-rails-api/test/test_helper.rb +0 -16
  135. data/lib/auth0/api/v1/clients.rb +0 -48
  136. data/lib/auth0/api/v1/connections.rb +0 -53
  137. data/lib/auth0/api/v1/logs.rb +0 -34
  138. data/lib/auth0/api/v1/rules.rb +0 -45
  139. data/lib/auth0/api/v1/users.rb +0 -164
  140. data/lib/auth0/api/v1.rb +0 -19
  141. data/publish_rubygem.sh +0 -10
  142. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_change_password/should_trigger_a_password_reset.yml +0 -63
  143. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_login_with_resource_owner/should_fail_with_an_incorrect_email.yml +0 -54
  144. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_login_with_resource_owner/should_fail_with_an_incorrect_password.yml +0 -54
  145. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_login_with_resource_owner/should_fail_with_an_invalid_audience.yml +0 -55
  146. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_login_with_resource_owner/should_login_successfully_with_a_custom_audience.yml +0 -117
  147. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_login_with_resource_owner/should_login_successfully_with_a_default_scope.yml +0 -119
  148. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_saml_metadata/should_retrieve_SAML_metadata.yml +0 -57
  149. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_userinfo/should_fail_as_not_authorized.yml +0 -55
  150. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_userinfo/should_return_the_userinfo.yml +0 -118
  151. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_wsfed_metadata/should_retrieve_WSFED_metadata.yml +0 -55
  152. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/create_test_user.yml +0 -58
  153. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/delete_test_user.yml +0 -54
  154. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Anomaly/_check_if_ip_is_blocked/should_return_200_response_code.yml +0 -65
  155. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Anomaly/_remove_ip_block/should_remove_an_IP_successfully.yml +0 -60
  156. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Blacklists/_add_token_to_blacklist/should_add_a_token_to_the_blacklist.yml +0 -56
  157. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Blacklists/_blacklisted_tokens/should_get_the_added_token_from_the_blacklist.yml +0 -59
  158. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_at_least_1_result.yml +0 -62
  159. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_the_first_page_of_one_result.yml +0 -66
  160. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_the_test_client_grant.yml +0 -62
  161. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_delete_client_grant/should_delete_the_test_client_grant.yml +0 -54
  162. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_patch_client_grant/should_update_the_test_client_grant.yml +0 -64
  163. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/create_test_client.yml +0 -118
  164. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/create_test_client_grant.yml +0 -64
  165. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/delete_test_client.yml +0 -54
  166. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/delete_test_client_grant.yml +0 -54
  167. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/_filters/should_exclude_and_include_fields_properly.yml +0 -91
  168. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/_filters/should_include_the_specified_fields.yml +0 -63
  169. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/should_get_the_test_client.yml +0 -92
  170. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_exclude_fields_not_specified.yml +0 -60
  171. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_exclude_the_specified_fields.yml +0 -132
  172. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_include_the_specified_fields.yml +0 -63
  173. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_paginate_results.yml +0 -65
  174. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/should_get_at_least_one_client.yml +0 -132
  175. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_delete_client/should_delete_the_test_client_without_an_error.yml +0 -54
  176. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_patch_client/should_update_the_client_with_the_correct_attributes.yml +0 -94
  177. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/create_test_client.yml +0 -118
  178. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/_filters/should_exclude_the_fields_indicated.yml +0 -63
  179. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/_filters/should_include_the_fields_indicated.yml +0 -61
  180. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/should_find_the_correct_connection.yml +0 -63
  181. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_include_previously-created_connection_when_filtered.yml +0 -59
  182. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_should_exclude_the_fields_indicated_from_filtered_results.yml +0 -59
  183. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_should_include_the_fields_indicated_from_filtered_results.yml +0 -59
  184. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/should_include_the_previously_created_connection.yml +0 -59
  185. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/should_not_be_empty.yml +0 -59
  186. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_delete_connection/should_delete_the_connection.yml +0 -54
  187. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_delete_connection_user/should_delete_the_user_created.yml +0 -110
  188. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_update_connection/should_update_the_connection.yml +0 -66
  189. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/create_test_connection.yml +0 -65
  190. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/create_test_user.yml +0 -68
  191. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/_delete_device_credential/should_delete_the_test_credential_without_an_error.yml +0 -54
  192. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/_device_credentials/_filter_by_type/should_exclude_the_test_credential.yml +0 -59
  193. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/_device_credentials/should_have_at_least_1_entry.yml +0 -62
  194. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/_device_credentials/should_include_the_test_credential.yml +0 -62
  195. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/create_test_credential.yml +0 -62
  196. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/create_test_user.yml +0 -68
  197. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/delete_test_credential.yml +0 -54
  198. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/delete_test_user.yml +0 -54
  199. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_configure_provider/should_configure_a_new_email_provider.yml +0 -63
  200. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_delete_provider/should_delete_the_existing_email_provider_without_an_error.yml +0 -54
  201. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_delete_provider/should_throw_an_error_trying_to_get_the_email_provider.yml +0 -51
  202. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/_filters/should_get_the_existing_email_provider_with_specific_fields.yml +0 -60
  203. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/_filters/should_get_the_existing_email_provider_without_specific_fields.yml +0 -61
  204. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/should_get_the_existing_email_provider.yml +0 -61
  205. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_update_provider/should_update_the_existing_email_provider.yml +0 -63
  206. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/delete_existing_provider.yml +0 -54
  207. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/_export_users_and_get_job/should_create_an_export_users_job_successfully.yml +0 -61
  208. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/_export_users_and_get_job/should_get_the_export_users_job.yml +0 -117
  209. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/_import_users_and_get_job/should_create_an_import_users_job_successfully.yml +0 -60
  210. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/_import_users_and_get_job/should_get_the_import_users_job.yml +0 -116
  211. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/_send_verification_email_and_get_job/should_create_a_new_verification_email_job.yml +0 -119
  212. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/_send_verification_email_and_get_job/should_get_the_completed_verification_email.yml +0 -175
  213. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/_send_verification_email_and_get_job/should_reject_an_invalid_client_id.yml +0 -109
  214. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/delete_imported_user.yml +0 -110
  215. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/search_for_connection_id.yml +0 -59
  216. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_log/should_match_the_created_log_entry.yml +0 -265
  217. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_log/should_not_be_empty.yml +0 -265
  218. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_exclude_fields_not_specified.yml +0 -61
  219. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_exclude_the_specified_fields.yml +0 -75
  220. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_have_one_log_entry.yml +0 -76
  221. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_include_the_specified_fields.yml +0 -62
  222. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_from/should_take_one_log_entry.yml +0 -258
  223. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/create_test_user.yml +0 -68
  224. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_disabled_rule.yml +0 -54
  225. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_enabled_rule.yml +0 -54
  226. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_user.yml +0 -54
  227. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/_delete_resource_server/should_delete_the_test_server_without_an_error.yml +0 -54
  228. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/_patch_resource_server/should_update_the_resource_server_with_the_correct_attributes.yml +0 -61
  229. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/_resource_server/should_get_the_test_server.yml +0 -59
  230. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/_resource_servers/should_get_the_test_server.yml +0 -59
  231. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/_resource_servers/should_return_at_least_1_result.yml +0 -59
  232. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/_resource_servers/should_return_the_first_page_of_one_result.yml +0 -64
  233. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/create_test_server.yml +0 -61
  234. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/delete_test_server.yml +0 -54
  235. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_add_role_permissions/should_add_a_Permission_to_the_Role_successfully.yml +0 -69
  236. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_add_role_users/should_add_a_User_to_the_Role_successfully.yml +0 -69
  237. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_delete_role/should_delete_the_Role_successfully.yml +0 -62
  238. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role/should_get_the_Role_successfully.yml +0 -67
  239. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_permissions/should_get_exactly_1_Permission.yml +0 -67
  240. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_permissions/should_get_the_added_Permission_from_the_Role_successfully.yml +0 -67
  241. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_users/should_get_exactly_1_User.yml +0 -67
  242. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_users/should_get_the_added_User_from_the_Role_successfully.yml +0 -67
  243. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_roles/should_get_the_Role_successfully.yml +0 -67
  244. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_remove_role_permissions/should_remove_a_Permission_from_the_Role_successfully.yml +0 -64
  245. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_update_role/should_update_the_Role_successfully.yml +0 -69
  246. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_api.yml +0 -69
  247. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_role.yml +0 -69
  248. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_user.yml +0 -69
  249. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/delete_test_api.yml +0 -62
  250. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/delete_test_user.yml +0 -62
  251. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_delete_rule/should_delete_the_test_disabled_rule_without_an_error.yml +0 -54
  252. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_delete_rule/should_delete_the_test_enabled_rule_without_an_error.yml +0 -54
  253. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_exclude_the_fields_not_specified.yml +0 -62
  254. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_exclude_the_specified_fields.yml +0 -62
  255. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_include_the_specified_fields.yml +0 -61
  256. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/should_get_a_specific_rule.yml +0 -62
  257. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_exclude_fields_not_specified.yml +0 -60
  258. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_include_the_specified_fields.yml +0 -61
  259. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_at_least_1_disabled_rule.yml +0 -63
  260. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_at_least_1_enabled_rule.yml +0 -62
  261. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_paginated_results.yml +0 -128
  262. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/should_return_at_least_1_rule.yml +0 -64
  263. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_update_rule/should_update_the_disabled_rule_to_be_enabled.yml +0 -64
  264. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/create_test_disabled_rule.yml +0 -65
  265. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/create_test_enabled_rule.yml +0 -65
  266. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Stats/_active_users/should_have_at_least_one_active_user.yml +0 -59
  267. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Stats/_daily_stats/should_have_at_least_one_stats_entry_for_the_timeframe.yml +0 -63
  268. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings/should_get_the_tenant_settings.yml +0 -95
  269. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings_with_specific_fields/should_exclude_a_field_not_requested.yml +0 -61
  270. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings_with_specific_fields/should_include_the_field_requested.yml +0 -61
  271. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_update_tenant_settings/should_revert_the_tenant_name.yml +0 -96
  272. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_update_tenant_settings/should_update_the_tenant_settings_with_a_new_tenant_name.yml +0 -96
  273. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/_post_email_verification/should_create_an_email_verification_ticket.yml +0 -63
  274. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/_post_password_change/should_create_a_password_change_ticket.yml +0 -63
  275. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/create_test_user.yml +0 -68
  276. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/delete_test_user.yml +0 -54
  277. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_add_user_permissions/should_add_a_Permissions_for_a_User_successfully.yml +0 -67
  278. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_add_user_roles/should_add_a_Role_to_a_User_successfully.yml +0 -62
  279. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_delete_user/should_delete_the_User_successfully.yml +0 -60
  280. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_delete_user/should_delete_the_secondary_User_successfully.yml +0 -60
  281. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_delete_user_provider/should_attempt_to_delete_the_MFA_provider_for_the_User.yml +0 -60
  282. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_enrollments/should_get_Enrollments_for_a_User_successfully.yml +0 -65
  283. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_permissions/should_get_exactly_1_Permission_for_a_User_successfully.yml +0 -65
  284. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_permissions/should_get_the_correct_Permission_for_a_User_successfully.yml +0 -65
  285. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_roles/should_get_Roles_for_a_User_successfully.yml +0 -65
  286. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_invalidate_browsers/should_invalidate_MFA_browsers_for_the_User_successfully.yml +0 -62
  287. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_link_user_account/should_link_two_Users_successfully.yml +0 -67
  288. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_patch_user/should_patch_the_User_successfully.yml +0 -68
  289. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_remove_user_permissions/should_remove_a_Permission_from_a_User_successfully.yml +0 -62
  290. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_remove_user_roles/should_remove_a_Role_from_a_User_successfully.yml +0 -62
  291. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_unlink_user_account/should_unlink_two_Users_successfully.yml +0 -65
  292. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_exclude_fields_not_indicated.yml +0 -65
  293. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_exclude_the_fields_indicated.yml +0 -65
  294. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_include_the_fields_indicated.yml +0 -65
  295. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/should_retrieve_the_created_user.yml +0 -65
  296. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user_logs/should_get_Logs_for_a_User_successfully.yml +0 -69
  297. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/is_expected_to_find_a_user_with_a_v2_search_engine_query.yml +0 -65
  298. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/is_expected_to_find_a_user_with_a_v3_search_engine_query.yml +0 -65
  299. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_exclude_the_indicated_fields_when_paginated.yml +0 -65
  300. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_include_the_indicated_fields_when_paginated.yml +0 -65
  301. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_not_include_other_fields_when_paginated.yml +0 -65
  302. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_return_the_correct_number_of_results_when_paginated.yml +0 -65
  303. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/should_have_at_least_one_user.yml +0 -65
  304. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_secondary_test_user.yml +0 -67
  305. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_api.yml +0 -67
  306. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_role.yml +0 -67
  307. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_user.yml +0 -67
  308. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/delete_test_api.yml +0 -60
  309. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/delete_test_role.yml +0 -60
  310. data/spec/integration/lib/auth0/api/api_authentication_spec.rb +0 -120
  311. data/spec/integration/lib/auth0/api/v2/api_anomaly_spec.rb +0 -17
  312. data/spec/integration/lib/auth0/api/v2/api_blacklist_spec.rb +0 -27
  313. data/spec/integration/lib/auth0/api/v2/api_client_grants_spec.rb +0 -75
  314. data/spec/integration/lib/auth0/api/v2/api_clients_spec.rb +0 -166
  315. data/spec/integration/lib/auth0/api/v2/api_connections_spec.rb +0 -159
  316. data/spec/integration/lib/auth0/api/v2/api_device_credentials_spec.rb +0 -128
  317. data/spec/integration/lib/auth0/api/v2/api_email_spec.rb +0 -117
  318. data/spec/integration/lib/auth0/api/v2/api_jobs_spec.rb +0 -112
  319. data/spec/integration/lib/auth0/api/v2/api_logs_spec.rb +0 -91
  320. data/spec/integration/lib/auth0/api/v2/api_resource_servers_spec.rb +0 -130
  321. data/spec/integration/lib/auth0/api/v2/api_roles_spec.rb +0 -145
  322. data/spec/integration/lib/auth0/api/v2/api_rules_spec.rb +0 -177
  323. data/spec/integration/lib/auth0/api/v2/api_stats_spec.rb +0 -22
  324. data/spec/integration/lib/auth0/api/v2/api_tenants_spec.rb +0 -59
  325. data/spec/integration/lib/auth0/api/v2/api_tickets_spec.rb +0 -53
  326. data/spec/integration/lib/auth0/api/v2/api_user_blocks_spec.rb +0 -73
  327. data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +0 -300
  328. data/spec/integration/lib/auth0/auth0_client_spec.rb +0 -90
  329. data/spec/lib/auth0/api/authentication_endpoints_spec.rb +0 -678
  330. data/spec/lib/auth0/api/v2/anomaly_spec.rb +0 -26
  331. data/spec/lib/auth0/api/v2/blacklists_spec.rb +0 -25
  332. data/spec/lib/auth0/api/v2/client_grants_spec.rb +0 -76
  333. data/spec/lib/auth0/api/v2/clients_spec.rb +0 -104
  334. data/spec/lib/auth0/api/v2/connections_spec.rb +0 -140
  335. data/spec/lib/auth0/api/v2/device_credentials_spec.rb +0 -73
  336. data/spec/lib/auth0/api/v2/emails_spec.rb +0 -47
  337. data/spec/lib/auth0/api/v2/guardian_spec.rb +0 -154
  338. data/spec/lib/auth0/api/v2/jobs_spec.rb +0 -111
  339. data/spec/lib/auth0/api/v2/logs_spec.rb +0 -48
  340. data/spec/lib/auth0/api/v2/resource_servers_spec.rb +0 -86
  341. data/spec/lib/auth0/api/v2/roles_spec.rb +0 -362
  342. data/spec/lib/auth0/api/v2/rules_spec.rb +0 -95
  343. data/spec/lib/auth0/api/v2/stats_spec.rb +0 -22
  344. data/spec/lib/auth0/api/v2/tenants_spec.rb +0 -26
  345. data/spec/lib/auth0/api/v2/tickets_spec.rb +0 -46
  346. data/spec/lib/auth0/api/v2/user_blocks_spec.rb +0 -52
  347. data/spec/lib/auth0/api/v2/users_by_email_spec.rb +0 -21
  348. data/spec/lib/auth0/api/v2/users_spec.rb +0 -525
  349. data/spec/lib/auth0/client_spec.rb +0 -153
  350. data/spec/lib/auth0/mixins/httpproxy_spec.rb +0 -304
  351. data/spec/lib/auth0/mixins/initializer_spec.rb +0 -30
  352. data/spec/spec_helper.rb +0 -62
  353. data/spec/support/credentials.rb +0 -30
  354. data/spec/support/dummy_class.rb +0 -18
  355. data/spec/support/dummy_class_for_proxy.rb +0 -5
  356. data/spec/support/dummy_class_for_restclient.rb +0 -2
  357. data/spec/support/import_users.json +0 -13
  358. data/spec/support/stub_response.rb +0 -1
@@ -1,39 +1,54 @@
1
+ # frozen_string_literal: true
1
2
  # rubocop:disable Metrics/ModuleLength
3
+
4
+ require 'jwt'
5
+ require_relative '../client_assertion'
6
+
2
7
  module Auth0
3
8
  module Api
4
9
  # {https://auth0.com/docs/api/authentication}
5
10
  # Methods to use the Authentication API
6
11
  module AuthenticationEndpoints
12
+ include Auth0::ClientAssertion
13
+
7
14
  UP_AUTH = 'Username-Password-Authentication'.freeze
8
15
  JWT_BEARER = 'urn:ietf:params:oauth:grant-type:jwt-bearer'.freeze
16
+ GRANT_TYPE_PASSWORDLESS_OPT = 'http://auth0.com/oauth/grant-type/passwordless/otp'.freeze
9
17
 
10
18
  # Request an API access token using a Client Credentials grant
11
19
  # @see https://auth0.com/docs/api-auth/tutorials/client-credentials
20
+ # @param client_id [string] Client ID for the application
21
+ # @param client_secret [string] Client secret for the application. Ignored if using Client Assertion
12
22
  # @param audience [string] API audience to use
23
+ # @param organization [string] Organization ID
13
24
  # @return [json] Returns the API token
14
25
  def api_token(
15
26
  client_id: @client_id,
16
27
  client_secret: @client_secret,
17
- audience: "https://#{@domain}/api/v2/"
28
+ organization: @organization,
29
+ audience: nil
18
30
  )
19
31
  request_params = {
20
32
  grant_type: 'client_credentials',
21
33
  client_id: client_id,
22
- client_secret: client_secret,
23
- audience: audience
34
+ audience: audience,
35
+ organization: organization
24
36
  }
25
- response = post('/oauth/token', request_params)
26
- ApiToken.new(response['access_token'], response['scope'], response['expires_in'])
37
+
38
+ populate_client_assertion_or_secret(request_params, client_id: client_id, client_secret: client_secret)
39
+
40
+ response = request_with_retry(:post, '/oauth/token', request_params)
41
+ ::Auth0::ApiToken.new(response['access_token'], response['scope'], response['expires_in'])
27
42
  end
28
43
 
29
44
  # Get access and ID tokens using an Authorization Code.
30
45
  # @see https://auth0.com/docs/api/authentication#authorization-code
31
46
  # @param code [string] The authentication code obtained from /authorize
32
47
  # @param redirect_uri [string] URL to redirect to after authorization.
48
+ # @param client_id [string] Client ID for the application
49
+ # @param client_secret [string] Client secret for the application. Ignored if using Client Assertion
33
50
  # Required only if it was set at the GET /authorize endpoint
34
- # @param client_id [string] Client ID for the Application
35
- # @param client_secret [string] Client Secret for the Application.
36
- # @return [AccessToken] Returns the access_token and id_token
51
+ # @return [Auth0::AccessToken] Returns the access_token and id_token
37
52
  def exchange_auth_code_for_tokens(
38
53
  code,
39
54
  redirect_uri: nil,
@@ -44,23 +59,25 @@ module Auth0
44
59
 
45
60
  request_params = {
46
61
  grant_type: 'authorization_code',
47
- client_id: client_id,
48
- client_secret: client_secret,
62
+ client_id: client_id,
49
63
  code: code,
50
64
  redirect_uri: redirect_uri
51
65
  }
52
- AccessToken.from_response post('/oauth/token', request_params)
66
+
67
+ populate_client_assertion_or_secret(request_params, client_id: client_id, client_secret: client_secret)
68
+
69
+ ::Auth0::AccessToken.from_response request_with_retry(:post, '/oauth/token', request_params)
53
70
  end
54
71
 
55
72
  # Get access and ID tokens using a refresh token.
56
73
  # @see https://auth0.com/docs/api/authentication#refresh-token
57
74
  # @param refresh_token [string] Refresh token to use. Request this with
58
75
  # the offline_access scope when logging in.
59
- # @param client_id [string] Client ID for the Application
60
- # @param client_secret [string] Client Secret for the Application.
76
+ # @param client_id [string] Client ID for the application
77
+ # @param client_secret [string] Client secret for the application. Ignored if using Client Assertion
61
78
  # Required when the Application's Token Endpoint Authentication Method
62
79
  # is Post or Basic.
63
- # @return [AccessToken] Returns tokens allowed in the refresh_token
80
+ # @return [Auth0::AccessToken] Returns tokens allowed in the refresh_token
64
81
  def exchange_refresh_token(
65
82
  refresh_token,
66
83
  client_id: @client_id,
@@ -71,10 +88,54 @@ module Auth0
71
88
  request_params = {
72
89
  grant_type: 'refresh_token',
73
90
  client_id: client_id,
74
- client_secret: client_secret,
75
91
  refresh_token: refresh_token
76
92
  }
77
- AccessToken.from_response post('/oauth/token', request_params)
93
+
94
+ populate_client_assertion_or_secret(request_params, client_id: client_id, client_secret: client_secret)
95
+
96
+ ::Auth0::AccessToken.from_response request_with_retry(:post, '/oauth/token', request_params)
97
+ end
98
+
99
+ # Exchange an OTP recieved through SMS for ID and access tokens
100
+ # @param phone_number [string] The user's phone number used to receive the OTP
101
+ # @param otp [string] The OTP contained in the SMS
102
+ # @param audience [string] The audience for the access token (defaults to nil)
103
+ # @param scope [string] The scope (defaults to 'openid profile email')
104
+ def exchange_sms_otp_for_tokens(phone_number, otp, audience: nil, scope: nil)
105
+ request_params = {
106
+ grant_type: GRANT_TYPE_PASSWORDLESS_OPT,
107
+ client_id: @client_id,
108
+ username: phone_number,
109
+ otp: otp,
110
+ realm: 'sms',
111
+ audience: audience,
112
+ scope: scope || 'openid profile email'
113
+ }
114
+
115
+ populate_client_assertion_or_secret(request_params)
116
+
117
+ ::Auth0::AccessToken.from_response request_with_retry(:post, '/oauth/token', request_params)
118
+ end
119
+
120
+ # Exchange an OTP recieved through email for ID and access tokens
121
+ # @param email_address [string] The user's email address used to receive the OTP
122
+ # @param otp [string] The OTP contained in the email
123
+ # @param audience [string] The audience for the access token (defaults to nil)
124
+ # @param scope [string] The scope (defaults to 'openid profile email')
125
+ def exchange_email_otp_for_tokens(email_address, otp, audience: nil, scope: nil)
126
+ request_params = {
127
+ grant_type: GRANT_TYPE_PASSWORDLESS_OPT,
128
+ client_id: @client_id,
129
+ username: email_address,
130
+ otp: otp,
131
+ realm: 'email',
132
+ audience: audience,
133
+ scope: scope || 'openid profile email'
134
+ }
135
+
136
+ populate_client_assertion_or_secret(request_params)
137
+
138
+ ::Auth0::AccessToken.from_response request_with_retry(:post, '/oauth/token', request_params)
78
139
  end
79
140
 
80
141
  # rubocop:disable Metrics/ParameterLists
@@ -83,8 +144,8 @@ module Auth0
83
144
  # @see https://auth0.com/docs/api/authentication#resource-owner-password
84
145
  # @param login_name [string] Email or username for the connection
85
146
  # @param password [string] Password
86
- # @param client_id [string] Client ID from Application settings
87
- # @param client_secret [string] Client Secret from Application settings
147
+ # @param client_id [string] Client ID for the application
148
+ # @param client_secret [string] Client secret for the application. Ignored if using Client Assertion
88
149
  # @param realm [string] Specific realm to authenticate against
89
150
  # @param audience [string] API audience
90
151
  # @param scope [string] Scope(s) requested
@@ -108,13 +169,15 @@ module Auth0
108
169
  username: login_name,
109
170
  password: password,
110
171
  client_id: client_id,
111
- client_secret: client_secret,
112
172
  realm: realm,
113
173
  scope: scope,
114
174
  audience: audience,
115
175
  grant_type: realm ? 'http://auth0.com/oauth/grant-type/password-realm' : 'password'
116
176
  }
117
- AccessToken.from_response post('/oauth/token', request_params)
177
+
178
+ populate_client_assertion_or_secret(request_params, client_id: client_id, client_secret: client_secret)
179
+
180
+ ::Auth0::AccessToken.from_response request_with_retry(:post, '/oauth/token', request_params)
118
181
  end
119
182
  # rubocop:enable Metrics/ParameterLists
120
183
 
@@ -134,16 +197,18 @@ module Auth0
134
197
  connection: connection_name,
135
198
  client_id: @client_id
136
199
  }
137
- post('/dbconnections/signup', request_params)
200
+
201
+ request_with_retry(:post, '/dbconnections/signup', request_params)
138
202
  end
139
203
 
140
204
  # Change a user's password or trigger a password reset email.
141
205
  # @see https://auth0.com/docs/api/authentication#change-password
142
206
  # @see https://auth0.com/docs/connections/database/password-change
143
207
  # @param email [string] User's current email
144
- # @param password [string] User's new password; empty to trigger a
145
- # password reset email
208
+ # @param password [string] User's new password. This is only available
209
+ # on legacy tenants with change password v1 flow enabled
146
210
  # @param connection_name [string] Database connection name
211
+ # @deprecated Use {#reset_password} instead.
147
212
  def change_password(email, password, connection_name = UP_AUTH)
148
213
  raise Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty?
149
214
 
@@ -153,7 +218,27 @@ module Auth0
153
218
  connection: connection_name,
154
219
  client_id: @client_id
155
220
  }
156
- post('/dbconnections/change_password', request_params)
221
+
222
+ request_with_retry(:post, '/dbconnections/change_password', request_params)
223
+ end
224
+
225
+ # Trigger a password reset email.
226
+ # @see https://auth0.com/docs/api/authentication#change-password
227
+ # @see https://auth0.com/docs/connections/database/password-change
228
+ # @param email [string] User's current email
229
+ # @param connection_name [string] Database connection name
230
+ # @param client_id [string] Client ID override (to allow forwarding
231
+ # to a different application's login URI on password reset success page)
232
+ def reset_password(email, connection_name = UP_AUTH, client_id = @client_id)
233
+ raise Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty?
234
+
235
+ request_params = {
236
+ email: email,
237
+ connection: connection_name,
238
+ client_id: client_id
239
+ }
240
+
241
+ request_with_retry(:post, '/dbconnections/change_password', request_params)
157
242
  end
158
243
 
159
244
  # Start Passwordless email login flow.
@@ -171,9 +256,11 @@ module Auth0
171
256
  authParams: auth_params,
172
257
  connection: 'email',
173
258
  client_id: @client_id,
174
- client_secret: @client_secret
175
259
  }
176
- post('/passwordless/start', request_params)
260
+
261
+ populate_client_assertion_or_secret(request_params)
262
+
263
+ request_with_retry(:post, '/passwordless/start', request_params)
177
264
  end
178
265
 
179
266
  # Start Passwordless SMS login flow.
@@ -187,36 +274,38 @@ module Auth0
187
274
  phone_number: phone_number,
188
275
  connection: 'sms',
189
276
  client_id: @client_id,
190
- client_secret: @client_secret
191
277
  }
192
- post('/passwordless/start', request_params)
278
+
279
+ populate_client_assertion_or_secret(request_params)
280
+
281
+ request_with_retry(:post, '/passwordless/start', request_params)
193
282
  end
194
283
 
195
284
  # Retrive SAML 2.0 metadata XML for an Application.
196
285
  # @see https://auth0.com/docs/api/authentication#get-metadata
197
286
  # @return [xml] SAML 2.0 metadata
198
287
  def saml_metadata
199
- get("/samlp/metadata/#{@client_id}")
288
+ request_with_retry(:get, "/samlp/metadata/#{@client_id}")
200
289
  end
201
290
 
202
291
  # Retrieve WS-Federation metadata XML for a tenant.
203
292
  # @see https://auth0.com/docs/api/authentication#get-metadata36
204
293
  # @return [xml] WS-Federation metadata
205
294
  def wsfed_metadata
206
- get('/wsfed/FederationMetadata/2007-06/FederationMetadata.xml')
295
+ request_with_retry(:get, '/wsfed/FederationMetadata/2007-06/FederationMetadata.xml')
207
296
  end
208
297
 
209
298
  # Return the user information based on the Auth0 access token.
210
299
  # @see https://auth0.com/docs/api/authentication#get-user-info
211
300
  # @return [json] User information based on the Auth0 access token
212
301
  def userinfo(access_token)
213
- get('/userinfo', {}, 'Authorization' => "Bearer #{access_token}")
302
+ request_with_retry(:get, '/userinfo', {}, 'Authorization' => "Bearer #{access_token}")
214
303
  end
215
304
 
216
305
  # Return an authorization URL.
217
306
  # @see https://auth0.com/docs/api/authentication#authorization-code-grant
218
307
  # @param redirect_uri [string] URL to redirect after authorization
219
- # @param options [hash] Can contain response_type, connection, state and additional_parameters.
308
+ # @param options [hash] Can contain response_type, connection, state, organization, invitation, and additional_parameters.
220
309
  # @return [url] Authorization URL.
221
310
  def authorization_url(redirect_uri, options = {})
222
311
  raise Auth0::InvalidParameter, 'Must supply a valid redirect_uri' if redirect_uri.to_s.empty?
@@ -227,12 +316,29 @@ module Auth0
227
316
  connection: options.fetch(:connection, nil),
228
317
  redirect_uri: redirect_uri,
229
318
  state: options.fetch(:state, nil),
230
- scope: options.fetch(:scope, nil)
319
+ scope: options.fetch(:scope, nil),
320
+ organization: options.fetch(:organization, @organization),
321
+ invitation: options.fetch(:invitation, nil)
231
322
  }.merge(options.fetch(:additional_parameters, {}))
232
323
 
233
324
  URI::HTTPS.build(host: @domain, path: '/authorize', query: to_query(request_params))
234
325
  end
235
326
 
327
+ # Return an authorization URL for PAR requests
328
+ # @see https://www.rfc-editor.org/rfc/rfc9126.html
329
+ # @param request_uri [string] The request_uri as obtained by calling `pushed_authorization_request`
330
+ # @param additional_parameters Any additional parameters to send
331
+ def par_authorization_url(request_uri)
332
+ raise Auth0::InvalidParameter, 'Must supply a valid request_uri' if request_uri.to_s.empty?
333
+
334
+ request_params = {
335
+ client_id: @client_id,
336
+ request_uri: request_uri,
337
+ }
338
+
339
+ URI::HTTPS.build(host: @domain, path: '/authorize', query: to_query(request_params))
340
+ end
341
+
236
342
  # Returns an Auth0 logout URL with a return URL.
237
343
  # @see https://auth0.com/docs/api/authentication#logout
238
344
  # @see https://auth0.com/docs/logout
@@ -254,6 +360,28 @@ module Auth0
254
360
  )
255
361
  end
256
362
 
363
+ # Make a request to the PAR endpoint and receive a `request_uri` to send to the '/authorize' endpoint.
364
+ # @see https://auth0.com/docs/api/authentication#authorization-code-grant
365
+ # @param redirect_uri [string] URL to redirect after authorization
366
+ # @param options [hash] Can contain response_type, connection, state, organization, invitation, and additional_parameters.
367
+ # @return [url] Authorization URL.
368
+ def pushed_authorization_request(parameters = {})
369
+ request_params = {
370
+ client_id: @client_id,
371
+ response_type: parameters.fetch(:response_type, 'code'),
372
+ connection: parameters.fetch(:connection, nil),
373
+ redirect_uri: parameters.fetch(:redirect_uri, nil),
374
+ state: parameters.fetch(:state, nil),
375
+ scope: parameters.fetch(:scope, nil),
376
+ organization: parameters.fetch(:organization, nil),
377
+ invitation: parameters.fetch(:invitation, nil)
378
+ }.merge(parameters.fetch(:additional_parameters, {}))
379
+
380
+ populate_client_assertion_or_secret(request_params)
381
+
382
+ request_with_retry(:post_form, '/oauth/par', request_params, {})
383
+ end
384
+
257
385
  # Return a SAMLP URL.
258
386
  # The SAML Request AssertionConsumerServiceURL will be used to POST back
259
387
  # the assertion and it must match with the application callback URL.
@@ -288,219 +416,38 @@ module Auth0
288
416
  )
289
417
  end
290
418
 
291
- #
292
- # DEPRECATED
293
- #
294
-
295
- # Retrieve an access token.
296
- # @deprecated 4.6.0 - Use the api_token method instead.
297
- # @see https://auth0.com/docs/api/authentication#client-credentials
298
- # @param access_token [string] Social provider's access_token
299
- # @param connection [string] Currently, this endpoint only works for Facebook, Google, Twitter and Weibo
300
- # @return [json] Returns the access token
301
- def obtain_access_token(access_token = nil, connection = 'facebook', scope = 'openid')
302
- if access_token
303
- request_params = { client_id: @client_id, access_token: access_token, connection: connection, scope: scope }
304
- post('/oauth/access_token', request_params)['access_token']
305
- else
306
- request_params = { client_id: @client_id, client_secret: @client_secret, grant_type: 'client_credentials' }
307
- post('/oauth/token', request_params)['access_token']
308
- end
309
- end
310
-
311
- # Get access and ID tokens using an Authorization Code.
312
- # @deprecated 4.6.0 - Use the exchange_auth_code_for_tokens method instead.
313
- # @see https://auth0.com/docs/api/authentication#authorization-code
314
- # @param code [string] The access code obtained through passive authentication
315
- # @param redirect_uri [string] Url to redirect after authorization
316
- # @param connection [string] Currently, this endpoint only works for Facebook, Google, Twitter and Weibo
317
- # @param scope [string] Defaults to openid. Can be 'openid name email', 'openid offline_access'
318
- # @return [json] Returns the access_token and id_token
319
- def obtain_user_tokens(code, redirect_uri, connection = 'facebook', scope = 'openid')
320
- raise Auth0::InvalidParameter, 'Must supply a valid code' if code.to_s.empty?
321
- raise Auth0::InvalidParameter, 'Must supply a valid redirect_uri' if redirect_uri.to_s.empty?
322
-
323
- request_params = {
324
- client_id: @client_id,
325
- client_secret: @client_secret,
326
- connection: connection,
327
- grant_type: 'authorization_code',
328
- code: code,
329
- scope: scope,
330
- redirect_uri: redirect_uri
331
- }
332
- post('/oauth/token', request_params)
333
- end
334
-
335
- # Get access and ID tokens using Resource Owner Password.
336
- # @deprecated 4.6.0 - Use the login_with_resource_owner method instead.
337
- # @see https://auth0.com/docs/api/authentication#resource-owner-password
338
- # @param username [string] Username or email
339
- # @param password [string] Password
340
- # @param id_token [string] Token's id
341
- # @param connection_name [string] Connection name; use a database or
342
- # passwordless connection, Active Directory/LDAP, Windows Azure or ADF
343
- # @param options [hash] Additional options - :scope, :grant_type, :device
344
- # @return [json] Returns the access_token and id_token
345
- def login(username, password, id_token = nil, connection_name = UP_AUTH, options = {})
346
- raise Auth0::InvalidParameter, 'Must supply a valid username' if username.to_s.empty?
347
- raise Auth0::InvalidParameter, 'Must supply a valid password' if password.to_s.empty?
348
-
349
- request_params = {
350
- client_id: @client_id,
351
- client_secret: @client_secret,
352
- username: username,
353
- password: password,
354
- scope: options.fetch(:scope, 'openid'),
355
- connection: connection_name,
356
- grant_type: options.fetch(:grant_type, 'password'),
357
- id_token: id_token,
358
- device: options.fetch(:device, nil)
359
- }
360
- post('/oauth/token', request_params)
361
- end
362
-
363
- # Return the user information based on the Auth0 access token.
364
- # @deprecated 4.6.0 - Use the userinfo method instead.
365
- # @see https://auth0.com/docs/api/authentication#get-user-info
366
- # @return [json] User information based on the Auth0 access token
367
- def user_info
368
- get('/userinfo')
369
- end
370
-
371
- # Login using phone number + verification code.
372
- # @deprecated 4.5.0 - Legacy authentication pipeline; use a Password Grant
373
- # instead - https://auth0.com/docs/api-auth/tutorials/password-grant
374
- # @see https://auth0.com/docs/api/authentication#resource-owner
375
- # @param phone_number [string] User's phone number.
376
- # @param code [string] Verification code.
377
- # @return [json] Returns the access token and id token
378
- def phone_login(phone_number, code, scope = 'openid')
379
- raise Auth0::InvalidParameter, 'Must supply a valid phone number' if phone_number.to_s.empty?
380
- raise Auth0::InvalidParameter, 'Must supply a valid code' if code.to_s.empty?
381
-
382
- request_params = {
383
- client_id: @client_id,
384
- username: phone_number,
385
- password: code,
386
- scope: scope,
387
- connection: 'sms',
388
- grant_type: 'password'
419
+ # Validate an ID token (signature and expiration).
420
+ # @see https://auth0.com/docs/tokens/guides/validate-id-tokens
421
+ # @param id_token [string] The JWT to validate.
422
+ # @param algorithm [JWKAlgorithm] The expected signing algorithm.
423
+
424
+ # @param leeway [integer] The clock skew to accept when verifying date related claims in seconds.
425
+ # Must be a non-negative value. Defaults to *60 seconds*.
426
+ # @param nonce [string] The nonce value sent during authentication.
427
+ # @param max_age [integer] The max_age value sent during authentication.
428
+ # Must be a non-negative value.
429
+ # @param issuer [string] The expected issuer claim value.
430
+ # Defaults to +https://YOUR_AUTH0_DOMAIN/+.
431
+ # @param audience [string] The expected audience claim value.
432
+ # Defaults to your *Auth0 Client ID*.
433
+ # @param organization [string] Organization ID
434
+ # Defaults to your *Auth0 Organization ID*.
435
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/ParameterLists
436
+ def validate_id_token(id_token, algorithm: nil, leeway: 60, nonce: nil, max_age: nil, issuer: nil, audience: nil, organization: @organization)
437
+ context = {
438
+ issuer: issuer || "https://#{@domain}/",
439
+ audience: audience || @client_id,
440
+ algorithm: algorithm || Auth0::Algorithm::RS256.jwks_url("https://#{@domain}/.well-known/jwks.json"),
441
+ leeway: leeway
389
442
  }
390
- post('/oauth/ro', request_params)
391
- end
392
-
393
- # Validate a JSON Web Token (signature and expiration).
394
- # @deprecated 4.5.0 - Legacy endpoint, use /userinfo instead.
395
- # @see https://auth0.com/docs/api/authentication#get-token-info
396
- # @param id_token [string] ID Token to use
397
- # @return User information associated with the user id (sub property) of the token.
398
- def token_info(id_token)
399
- raise Auth0::InvalidParameter, 'Must supply a valid id_token' if id_token.to_s.empty?
400
-
401
- request_params = { id_token: id_token }
402
- post('/tokeninfo', request_params)
403
- end
404
443
 
405
- # Refresh a delegation token.
406
- # @deprecated 4.5.0 - Feature is disabled, no replacement currently; see
407
- # https://auth0.com/docs/api-auth/tutorials/adoption/delegation
408
- # @see https://auth0.com/docs/api/authentication#delegation
409
- # @param refresh_token [string] Token to refresh
410
- # @param target [string] Target to sign the new token.
411
- # @param scope [string] Defaults to openid. Can be 'openid name email'.
412
- # @param api_type [string] Defaults to app. Can be aws, azure_sb, azure_blob, firebase, layer, salesforce_api,
413
- # salesforce_sandbox_api, sap_api or wams
414
- # @param extra_parameters [hash] Extra parameters.
415
- # @return [json] Returns the refreshed delegation token
416
- def refresh_delegation(refresh_token, target, scope = 'openid', api_type = 'app', extra_parameters = {})
417
- raise Auth0::InvalidParameter, 'Must supply a valid token to refresh' if refresh_token.to_s.empty?
444
+ context[:nonce] = nonce unless nonce.nil?
445
+ context[:max_age] = max_age unless max_age.nil?
446
+ context[:organization] = organization unless !organization
418
447
 
419
- request_params = {
420
- client_id: @client_id,
421
- grant_type: JWT_BEARER,
422
- refresh_token: refresh_token,
423
- target: target,
424
- api_type: api_type,
425
- scope: scope
426
- }.merge(extra_parameters)
427
- post('/delegation', request_params)
428
- end
429
-
430
- # Retrieve a delegation token.
431
- # @deprecated 4.5.0 - Feature is disabled, no replacement currently; see
432
- # https://auth0.com/docs/api-auth/tutorials/adoption/delegation
433
- # @see https://auth0.com/docs/api/authentication#delegation
434
- # @param id_token [string] Token's id.
435
- # @param target [string] Target to sign the new token.
436
- # @param scope [string] Defaults to openid. Can be 'openid name email'.
437
- # @param api_type [string] Defaults to app. Can be aws, azure_sb, azure_blob, firebase, layer, salesforce_api,
438
- # salesforce_sandbox_api, sap_api or wams
439
- # @param extra_parameters [hash] Extra parameters.
440
- # @return [json] Returns the refreshed delegation token
441
- def delegation(id_token, target, scope = 'openid', api_type = 'app', extra_parameters = {})
442
- raise Auth0::InvalidParameter, 'Must supply a valid id_token' if id_token.to_s.empty?
443
-
444
- request_params = {
445
- client_id: @client_id,
446
- grant_type: JWT_BEARER,
447
- id_token: id_token,
448
- target: target,
449
- api_type: api_type,
450
- scope: scope
451
- }.merge(extra_parameters)
452
- post('/delegation', request_params)
453
- end
454
-
455
- # Retrieve an impersonation URL to login as another user.
456
- # @deprecated 4.5.0 - Feature is disabled.
457
- # @see https://auth0.com/docs/api/authentication#impersonation
458
- # @param user_id [string] Impersonate user id
459
- # @param app_client_id [string] Application client id
460
- # @param impersonator_id [string] Impersonator user id id.
461
- # @param options [string] Additional Parameters
462
- # @return [string] Impersonation URL
463
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
464
- def impersonate(user_id, app_client_id, impersonator_id, options)
465
- raise Auth0::InvalidParameter, 'Must supply a valid user_id' if user_id.to_s.empty?
466
- raise Auth0::InvalidParameter, 'Must supply a valid app_client_id' if app_client_id.to_s.empty?
467
- raise Auth0::InvalidParameter, 'Must supply a valid impersonator_id' if impersonator_id.to_s.empty?
468
- raise Auth0::MissingParameter, 'Must supply client_secret' if @client_secret.nil?
469
-
470
- authorization_header obtain_access_token
471
- request_params = {
472
- protocol: options.fetch(:protocol, 'oauth2'),
473
- impersonator_id: impersonator_id,
474
- client_id: app_client_id,
475
- additionalParameters: {
476
- response_type: options.fetch(:response_type, 'code'),
477
- state: options.fetch(:state, ''),
478
- scope: options.fetch(:scope, 'openid'),
479
- callback_url: options.fetch(:callback_url, '')
480
- }
481
- }
482
- result = post("/users/#{user_id}/impersonate", request_params)
483
- authorization_header @token
484
- result
485
- end
486
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
487
-
488
- # Unlink a user's account from the identity provider.
489
- # @deprecated 4.5.0 - Endpoint is disabled in favor of the Management API;
490
- # see https://auth0.com/docs/migrations/guides/account-linking
491
- # @see https://auth0.com/docs/api/authentication#unlink
492
- # @param access_token [string] Logged-in user access token
493
- # @param user_id [string] User Id
494
- def unlink_user(access_token, user_id)
495
- raise Auth0::InvalidParameter, 'Must supply a valid access_token' if access_token.to_s.empty?
496
- raise Auth0::InvalidParameter, 'Must supply a valid user_id' if user_id.to_s.empty?
497
-
498
- request_params = {
499
- access_token: access_token,
500
- user_id: user_id
501
- }
502
- post('/unlink', request_params)
448
+ Auth0::Mixins::Validation::IdTokenValidator.new(context).validate(id_token)
503
449
  end
450
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/ParameterLists
504
451
 
505
452
  private
506
453