auth0 4.4.0 → 5.1.2

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 (289) hide show
  1. checksums.yaml +4 -4
  2. data/.bundle/config +3 -2
  3. data/.circleci/config.yml +44 -0
  4. data/.env.example +2 -0
  5. data/.github/CODEOWNERS +1 -0
  6. data/.github/ISSUE_TEMPLATE/config.yml +8 -0
  7. data/.github/ISSUE_TEMPLATE/feature_request.md +39 -0
  8. data/.github/ISSUE_TEMPLATE/report_a_bug.md +55 -0
  9. data/.github/PULL_REQUEST_TEMPLATE.md +35 -0
  10. data/.github/stale.yml +20 -0
  11. data/.gitignore +1 -2
  12. data/.rubocop.yml +2 -0
  13. data/.yardoc/checksums +22 -0
  14. data/.yardoc/complete +0 -0
  15. data/.yardoc/object_types +0 -0
  16. data/.yardoc/objects/root.dat +0 -0
  17. data/.yardoc/proxy_types +0 -0
  18. data/CHANGELOG.md +334 -19
  19. data/CODE_OF_CONDUCT.md +3 -0
  20. data/DEPLOYMENT.md +56 -9
  21. data/Gemfile +10 -3
  22. data/README.md +260 -37
  23. data/Rakefile +4 -23
  24. data/auth0.gemspec +10 -9
  25. data/codecov.yml +22 -0
  26. data/examples/ruby-api/.gitignore +0 -6
  27. data/lib/auth0/algorithm.rb +5 -0
  28. data/lib/auth0/api/authentication_endpoints.rb +244 -237
  29. data/lib/auth0/api/v2/anomaly.rb +36 -0
  30. data/lib/auth0/api/v2/branding.rb +66 -0
  31. data/lib/auth0/api/v2/client_grants.rb +14 -5
  32. data/lib/auth0/api/v2/clients.rb +9 -6
  33. data/lib/auth0/api/v2/connections.rb +19 -7
  34. data/lib/auth0/api/v2/device_credentials.rb +5 -4
  35. data/lib/auth0/api/v2/guardian.rb +142 -0
  36. data/lib/auth0/api/v2/jobs.rb +77 -13
  37. data/lib/auth0/api/v2/log_streams.rb +78 -0
  38. data/lib/auth0/api/v2/logs.rb +11 -11
  39. data/lib/auth0/api/v2/organizations.rb +335 -0
  40. data/lib/auth0/api/v2/prompts.rb +70 -0
  41. data/lib/auth0/api/v2/resource_servers.rb +32 -8
  42. data/lib/auth0/api/v2/roles.rb +172 -0
  43. data/lib/auth0/api/v2/rules.rb +6 -2
  44. data/lib/auth0/api/v2/tickets.rb +55 -8
  45. data/lib/auth0/api/v2/users.rb +168 -28
  46. data/lib/auth0/api/v2/users_by_email.rb +3 -2
  47. data/lib/auth0/api/v2.rb +16 -2
  48. data/lib/auth0/client.rb +1 -1
  49. data/lib/auth0/exception.rb +34 -9
  50. data/lib/auth0/mixins/access_token_struct.rb +20 -0
  51. data/lib/auth0/mixins/api_token_struct.rb +10 -0
  52. data/lib/auth0/mixins/headers.rb +35 -0
  53. data/lib/auth0/mixins/httpproxy.rb +37 -14
  54. data/lib/auth0/mixins/initializer.rb +10 -26
  55. data/lib/auth0/mixins/permission_struct.rb +3 -0
  56. data/lib/auth0/mixins/validation.rb +346 -0
  57. data/lib/auth0/mixins.rb +9 -1
  58. data/lib/auth0/version.rb +1 -1
  59. data/lib/auth0.rb +1 -0
  60. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_change_password/should_trigger_a_password_reset.yml +63 -0
  61. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_login_with_resource_owner/should_fail_with_an_incorrect_email.yml +54 -0
  62. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_login_with_resource_owner/should_fail_with_an_incorrect_password.yml +54 -0
  63. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_login_with_resource_owner/should_fail_with_an_invalid_audience.yml +55 -0
  64. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_login_with_resource_owner/should_login_successfully_with_a_custom_audience.yml +117 -0
  65. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_login_with_resource_owner/should_login_successfully_with_a_default_scope.yml +119 -0
  66. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_saml_metadata/should_retrieve_SAML_metadata.yml +57 -0
  67. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_userinfo/should_fail_as_not_authorized.yml +55 -0
  68. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_userinfo/should_return_the_userinfo.yml +118 -0
  69. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/_wsfed_metadata/should_retrieve_WSFED_metadata.yml +55 -0
  70. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/create_test_user.yml +58 -0
  71. data/spec/fixtures/vcr_cassettes/Auth0_Api_AuthenticationEndpoints/delete_test_user.yml +54 -0
  72. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Anomaly/_check_if_ip_is_blocked/should_return_200_response_code.yml +65 -0
  73. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Anomaly/_remove_ip_block/should_remove_an_IP_successfully.yml +60 -0
  74. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Blacklists/_add_token_to_blacklist/should_add_a_token_to_the_blacklist.yml +56 -0
  75. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Blacklists/_blacklisted_tokens/should_get_the_added_token_from_the_blacklist.yml +59 -0
  76. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_at_least_1_result.yml +62 -0
  77. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_the_first_page_of_one_result.yml +66 -0
  78. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_client_grants/should_return_the_test_client_grant.yml +62 -0
  79. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_delete_client_grant/should_delete_the_test_client_grant.yml +54 -0
  80. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/_patch_client_grant/should_update_the_test_client_grant.yml +64 -0
  81. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/create_test_client.yml +118 -0
  82. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/create_test_client_grant.yml +64 -0
  83. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/delete_test_client.yml +54 -0
  84. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ClientGrants/delete_test_client_grant.yml +54 -0
  85. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/_filters/should_exclude_and_include_fields_properly.yml +91 -0
  86. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/_filters/should_include_the_specified_fields.yml +63 -0
  87. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_client/should_get_the_test_client.yml +92 -0
  88. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_exclude_fields_not_specified.yml +60 -0
  89. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_exclude_the_specified_fields.yml +132 -0
  90. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_include_the_specified_fields.yml +63 -0
  91. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/_filters/should_paginate_results.yml +65 -0
  92. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_clients/should_get_at_least_one_client.yml +132 -0
  93. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_delete_client/should_delete_the_test_client_without_an_error.yml +54 -0
  94. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/_patch_client/should_update_the_client_with_the_correct_attributes.yml +94 -0
  95. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Clients/create_test_client.yml +118 -0
  96. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/_filters/should_exclude_the_fields_indicated.yml +63 -0
  97. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/_filters/should_include_the_fields_indicated.yml +61 -0
  98. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connection/should_find_the_correct_connection.yml +63 -0
  99. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_include_previously-created_connection_when_filtered.yml +59 -0
  100. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_should_exclude_the_fields_indicated_from_filtered_results.yml +59 -0
  101. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/_filters/should_should_include_the_fields_indicated_from_filtered_results.yml +59 -0
  102. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/should_include_the_previously_created_connection.yml +59 -0
  103. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_connections/should_not_be_empty.yml +59 -0
  104. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_delete_connection/should_delete_the_connection.yml +54 -0
  105. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_delete_connection_user/should_delete_the_user_created.yml +110 -0
  106. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/_update_connection/should_update_the_connection.yml +66 -0
  107. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/create_test_connection.yml +65 -0
  108. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Connections/create_test_user.yml +68 -0
  109. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/_delete_device_credential/should_delete_the_test_credential_without_an_error.yml +54 -0
  110. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/_device_credentials/_filter_by_type/should_exclude_the_test_credential.yml +59 -0
  111. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/_device_credentials/should_have_at_least_1_entry.yml +62 -0
  112. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/_device_credentials/should_include_the_test_credential.yml +62 -0
  113. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/create_test_credential.yml +62 -0
  114. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/create_test_user.yml +68 -0
  115. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/delete_test_credential.yml +54 -0
  116. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_DeviceCredentials/delete_test_user.yml +54 -0
  117. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_configure_provider/should_configure_a_new_email_provider.yml +63 -0
  118. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_delete_provider/should_delete_the_existing_email_provider_without_an_error.yml +54 -0
  119. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_delete_provider/should_throw_an_error_trying_to_get_the_email_provider.yml +51 -0
  120. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/_filters/should_get_the_existing_email_provider_with_specific_fields.yml +60 -0
  121. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/_filters/should_get_the_existing_email_provider_without_specific_fields.yml +61 -0
  122. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_get_provider/should_get_the_existing_email_provider.yml +61 -0
  123. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/_update_provider/should_update_the_existing_email_provider.yml +63 -0
  124. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Emails/delete_existing_provider.yml +54 -0
  125. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/_export_users_and_get_job/should_create_an_export_users_job_successfully.yml +61 -0
  126. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/_export_users_and_get_job/should_get_the_export_users_job.yml +117 -0
  127. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/_import_users_and_get_job/should_create_an_import_users_job_successfully.yml +60 -0
  128. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/_import_users_and_get_job/should_get_the_import_users_job.yml +116 -0
  129. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/_send_verification_email_and_get_job/should_create_a_new_verification_email_job.yml +119 -0
  130. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/_send_verification_email_and_get_job/should_get_the_completed_verification_email.yml +175 -0
  131. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/_send_verification_email_and_get_job/should_reject_an_invalid_client_id.yml +109 -0
  132. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/delete_imported_user.yml +110 -0
  133. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Jobs/search_for_connection_id.yml +59 -0
  134. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_log/should_match_the_created_log_entry.yml +265 -0
  135. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_log/should_not_be_empty.yml +265 -0
  136. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_exclude_fields_not_specified.yml +61 -0
  137. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_exclude_the_specified_fields.yml +75 -0
  138. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_have_one_log_entry.yml +76 -0
  139. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_filters/should_include_the_specified_fields.yml +62 -0
  140. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/_logs/_from/should_take_one_log_entry.yml +258 -0
  141. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/create_test_user.yml +68 -0
  142. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_disabled_rule.yml +54 -0
  143. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_enabled_rule.yml +54 -0
  144. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Logs/delete_test_user.yml +54 -0
  145. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/_delete_resource_server/should_delete_the_test_server_without_an_error.yml +54 -0
  146. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/_patch_resource_server/should_update_the_resource_server_with_the_correct_attributes.yml +61 -0
  147. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/_resource_server/should_get_the_test_server.yml +59 -0
  148. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/_resource_servers/should_get_the_test_server.yml +59 -0
  149. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/_resource_servers/should_return_at_least_1_result.yml +59 -0
  150. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/_resource_servers/should_return_the_first_page_of_one_result.yml +64 -0
  151. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/create_test_server.yml +61 -0
  152. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_ResourceServers/delete_test_server.yml +54 -0
  153. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_add_role_permissions/should_add_a_Permission_to_the_Role_successfully.yml +69 -0
  154. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_add_role_users/should_add_a_User_to_the_Role_successfully.yml +69 -0
  155. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_delete_role/should_delete_the_Role_successfully.yml +62 -0
  156. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role/should_get_the_Role_successfully.yml +67 -0
  157. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_permissions/should_get_exactly_1_Permission.yml +67 -0
  158. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_permissions/should_get_the_added_Permission_from_the_Role_successfully.yml +67 -0
  159. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_users/should_get_exactly_1_User.yml +67 -0
  160. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_role_users/should_get_the_added_User_from_the_Role_successfully.yml +67 -0
  161. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_get_roles/should_get_the_Role_successfully.yml +67 -0
  162. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_remove_role_permissions/should_remove_a_Permission_from_the_Role_successfully.yml +64 -0
  163. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/_update_role/should_update_the_Role_successfully.yml +69 -0
  164. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_api.yml +69 -0
  165. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_role.yml +69 -0
  166. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/create_test_user.yml +69 -0
  167. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/delete_test_api.yml +62 -0
  168. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Roles/delete_test_user.yml +62 -0
  169. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_delete_rule/should_delete_the_test_disabled_rule_without_an_error.yml +54 -0
  170. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_delete_rule/should_delete_the_test_enabled_rule_without_an_error.yml +54 -0
  171. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_exclude_the_fields_not_specified.yml +62 -0
  172. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_exclude_the_specified_fields.yml +62 -0
  173. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/_filters/should_include_the_specified_fields.yml +61 -0
  174. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rule/should_get_a_specific_rule.yml +62 -0
  175. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_exclude_fields_not_specified.yml +60 -0
  176. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_include_the_specified_fields.yml +61 -0
  177. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_at_least_1_disabled_rule.yml +63 -0
  178. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_at_least_1_enabled_rule.yml +62 -0
  179. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/_filters/should_return_paginated_results.yml +128 -0
  180. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_rules/should_return_at_least_1_rule.yml +64 -0
  181. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/_update_rule/should_update_the_disabled_rule_to_be_enabled.yml +64 -0
  182. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/create_test_disabled_rule.yml +65 -0
  183. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Rules/create_test_enabled_rule.yml +65 -0
  184. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Stats/_active_users/should_have_at_least_one_active_user.yml +59 -0
  185. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Stats/_daily_stats/should_have_at_least_one_stats_entry_for_the_timeframe.yml +63 -0
  186. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings/should_get_the_tenant_settings.yml +95 -0
  187. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings_with_specific_fields/should_exclude_a_field_not_requested.yml +61 -0
  188. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_get_tenant_settings_with_specific_fields/should_include_the_field_requested.yml +61 -0
  189. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_update_tenant_settings/should_revert_the_tenant_name.yml +96 -0
  190. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tenants/_update_tenant_settings/should_update_the_tenant_settings_with_a_new_tenant_name.yml +96 -0
  191. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/_post_email_verification/should_create_an_email_verification_ticket.yml +63 -0
  192. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/_post_password_change/should_create_a_password_change_ticket.yml +63 -0
  193. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/create_test_user.yml +68 -0
  194. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Tickets/delete_test_user.yml +54 -0
  195. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_add_user_permissions/should_add_a_Permissions_for_a_User_successfully.yml +67 -0
  196. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_add_user_roles/should_add_a_Role_to_a_User_successfully.yml +62 -0
  197. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_delete_user/should_delete_the_User_successfully.yml +60 -0
  198. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_delete_user/should_delete_the_secondary_User_successfully.yml +60 -0
  199. 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
  200. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_enrollments/should_get_Enrollments_for_a_User_successfully.yml +65 -0
  201. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_permissions/should_get_exactly_1_Permission_for_a_User_successfully.yml +65 -0
  202. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_permissions/should_get_the_correct_Permission_for_a_User_successfully.yml +65 -0
  203. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_get_user_roles/should_get_Roles_for_a_User_successfully.yml +65 -0
  204. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_invalidate_browsers/should_invalidate_MFA_browsers_for_the_User_successfully.yml +62 -0
  205. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_link_user_account/should_link_two_Users_successfully.yml +67 -0
  206. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_patch_user/should_patch_the_User_successfully.yml +68 -0
  207. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_remove_user_permissions/should_remove_a_Permission_from_a_User_successfully.yml +62 -0
  208. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_remove_user_roles/should_remove_a_Role_from_a_User_successfully.yml +62 -0
  209. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_unlink_user_account/should_unlink_two_Users_successfully.yml +65 -0
  210. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_exclude_fields_not_indicated.yml +65 -0
  211. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_exclude_the_fields_indicated.yml +65 -0
  212. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/_filters/should_include_the_fields_indicated.yml +65 -0
  213. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user/should_retrieve_the_created_user.yml +65 -0
  214. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_user_logs/should_get_Logs_for_a_User_successfully.yml +69 -0
  215. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/is_expected_to_find_a_user_with_a_v2_search_engine_query.yml +65 -0
  216. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/is_expected_to_find_a_user_with_a_v3_search_engine_query.yml +65 -0
  217. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_exclude_the_indicated_fields_when_paginated.yml +65 -0
  218. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_include_the_indicated_fields_when_paginated.yml +65 -0
  219. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_not_include_other_fields_when_paginated.yml +65 -0
  220. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/_filters/should_return_the_correct_number_of_results_when_paginated.yml +65 -0
  221. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/_users/should_have_at_least_one_user.yml +65 -0
  222. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_secondary_test_user.yml +67 -0
  223. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_api.yml +67 -0
  224. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_role.yml +67 -0
  225. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/create_test_user.yml +67 -0
  226. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/delete_test_api.yml +60 -0
  227. data/spec/fixtures/vcr_cassettes/Auth0_Api_V2_Users/delete_test_role.yml +60 -0
  228. data/spec/integration/lib/auth0/api/api_authentication_spec.rb +96 -54
  229. data/spec/integration/lib/auth0/api/v2/api_anomaly_spec.rb +17 -0
  230. data/spec/integration/lib/auth0/api/v2/api_blacklist_spec.rb +18 -5
  231. data/spec/integration/lib/auth0/api/v2/api_client_grants_spec.rb +46 -33
  232. data/spec/integration/lib/auth0/api/v2/api_clients_spec.rb +115 -61
  233. data/spec/integration/lib/auth0/api/v2/api_connections_spec.rb +117 -103
  234. data/spec/integration/lib/auth0/api/v2/api_device_credentials_spec.rb +101 -58
  235. data/spec/integration/lib/auth0/api/v2/api_email_spec.rb +72 -77
  236. data/spec/integration/lib/auth0/api/v2/api_jobs_spec.rb +113 -60
  237. data/spec/integration/lib/auth0/api/v2/api_logs_spec.rb +46 -38
  238. data/spec/integration/lib/auth0/api/v2/api_resource_servers_spec.rb +110 -40
  239. data/spec/integration/lib/auth0/api/v2/api_roles_spec.rb +145 -0
  240. data/spec/integration/lib/auth0/api/v2/api_rules_spec.rb +119 -62
  241. data/spec/integration/lib/auth0/api/v2/api_stats_spec.rb +11 -14
  242. data/spec/integration/lib/auth0/api/v2/api_tenants_spec.rb +40 -34
  243. data/spec/integration/lib/auth0/api/v2/api_tickets_spec.rb +42 -28
  244. data/spec/integration/lib/auth0/api/v2/api_user_blocks_spec.rb +1 -1
  245. data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +252 -120
  246. data/spec/integration/lib/auth0/auth0_client_spec.rb +32 -26
  247. data/spec/lib/auth0/api/v2/anomaly_spec.rb +26 -0
  248. data/spec/lib/auth0/api/v2/branding_spec.rb +70 -0
  249. data/spec/lib/auth0/api/v2/client_grants_spec.rb +34 -2
  250. data/spec/lib/auth0/api/v2/clients_spec.rb +50 -5
  251. data/spec/lib/auth0/api/v2/connections_spec.rb +49 -1
  252. data/spec/lib/auth0/api/v2/guardian_spec.rb +154 -0
  253. data/spec/lib/auth0/api/v2/jobs_spec.rb +109 -6
  254. data/spec/lib/auth0/api/v2/log_streams_spec.rb +84 -0
  255. data/spec/lib/auth0/api/v2/organizations_spec.rb +593 -0
  256. data/spec/lib/auth0/api/v2/prompts_spec.rb +88 -0
  257. data/spec/lib/auth0/api/v2/resource_servers_spec.rb +23 -0
  258. data/spec/lib/auth0/api/v2/roles_spec.rb +362 -0
  259. data/spec/lib/auth0/api/v2/rules_spec.rb +23 -1
  260. data/spec/lib/auth0/api/v2/tickets_spec.rb +95 -5
  261. data/spec/lib/auth0/api/v2/users_spec.rb +465 -61
  262. data/spec/lib/auth0/client_spec.rb +196 -18
  263. data/spec/lib/auth0/mixins/httpproxy_spec.rb +83 -4
  264. data/spec/lib/auth0/mixins/initializer_spec.rb +1 -0
  265. data/spec/lib/auth0/mixins/validation_spec.rb +498 -0
  266. data/spec/spec_helper.rb +54 -11
  267. data/spec/support/credentials.rb +6 -18
  268. data/spec/support/dummy_class.rb +7 -3
  269. data/spec/support/dummy_class_for_proxy.rb +1 -0
  270. data/spec/support/stub_response.rb +1 -1
  271. metadata +497 -53
  272. data/.travis.yml +0 -18
  273. data/build_travis.sh +0 -7
  274. data/deploy_documentation.sh +0 -29
  275. data/doc_config/templates/default/fulldoc/html/css/full_list.css +0 -79
  276. data/doc_config/templates/default/fulldoc/html/css/style.css +0 -546
  277. data/doc_config/templates/default/layout/html/breadcrumb.erb +0 -11
  278. data/doc_config/templates/default/layout/html/footer.erb +0 -115
  279. data/doc_config/templates/default/layout/html/headers.erb +0 -17
  280. data/doc_config/templates/default/layout/html/layout.erb +0 -27
  281. data/lib/auth0/api/v1/clients.rb +0 -48
  282. data/lib/auth0/api/v1/connections.rb +0 -53
  283. data/lib/auth0/api/v1/logs.rb +0 -34
  284. data/lib/auth0/api/v1/rules.rb +0 -45
  285. data/lib/auth0/api/v1/users.rb +0 -164
  286. data/lib/auth0/api/v1.rb +0 -19
  287. data/spec/lib/auth0/api/authentication_endpoints_spec.rb +0 -348
  288. data/spec/spec_helper_full.rb +0 -45
  289. data/spec/spec_helper_unit.rb +0 -3
@@ -0,0 +1,498 @@
1
+ # rubocop:disable Metrics/BlockLength
2
+ require 'spec_helper'
3
+
4
+ RSA_PUB_KEY_JWK_1 = { 'kty': "RSA", 'use': 'sig', 'n': "uGbXWiK3dQTyCbX5xdE4yCuYp0AF2d15Qq1JSXT_lx8CEcXb9RbDddl8jGDv-spi5qPa8qEHiK7FwV2KpRE983wGPnYsAm9BxLFb4YrLYcDFOIGULuk2FtrPS512Qea1bXASuvYXEpQNpGbnTGVsWXI9C-yjHztqyL2h8P6mlThPY9E9ue2fCqdgixfTFIF9Dm4SLHbphUS2iw7w1JgT69s7of9-I9l5lsJ9cozf1rxrXX4V1u_SotUuNB3Fp8oB4C1fLBEhSlMcUJirz1E8AziMCxS-VrRPDM-zfvpIJg3JljAh3PJHDiLu902v9w-Iplu1WyoB2aPfitxEhRN0Yw", 'e': 'AQAB', 'kid': 'test-key-1' }.freeze
5
+ RSA_PUB_KEY_JWK_2 = { 'kty': "RSA", 'use': 'sig', 'n': "uGbXWiK3dQTyCbX5xdE4yCuYp0AF2d15Qq1JSXT_lx8CEcXb9RbDddl8jGDv-spi5qPa8qEHiK7FwV2KpRE983wGPnYsAm9BxLFb4YrLYcDFOIGULuk2FtrPS512Qea1bXASuvYXEpQNpGbnTGVsWXI9C-yjHztqyL2h8P6mlThPY9E9ue2fCqdgixfTFIF9Dm4SLHbphUS2iw7w1JgT69s7of9-I9l5lsJ9cozf1rxrXX4V1u_SotUuNB3Fp8oB4C1fLBEhSlMcUJirz1E8AziMCxS-VrRPDM-zfvpIJg3JljAh3PJHDiLu902v9w-Iplu1WyoB2aPfitxEhRN0Yw", 'e': 'AQAB', 'kid': 'test-key-2' }.freeze
6
+ JWKS_RESPONSE_1 = { 'keys': [RSA_PUB_KEY_JWK_1] }.freeze
7
+ JWKS_RESPONSE_2 = { 'keys': [RSA_PUB_KEY_JWK_2] }.freeze
8
+ JWKS_URL = 'https://tokens-test.auth0.com/.well-known/jwks.json'.freeze
9
+ HMAC_SHARED_SECRET = 'secret'.freeze
10
+
11
+ LEEWAY = 60
12
+ CLOCK = 1587592561 # Apr 22 2020 21:56:01 UTC
13
+ CONTEXT = { algorithm: Auth0::Algorithm::HS256.secret(HMAC_SHARED_SECRET), leeway: LEEWAY, audience: 'tokens-test-123', issuer: 'https://tokens-test.auth0.com/', clock: CLOCK }.freeze
14
+
15
+ describe Auth0::Mixins::Validation::IdTokenValidator do
16
+ subject { @instance }
17
+
18
+ context 'instance' do
19
+ it 'is expected respond to :validate' do
20
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new({})
21
+
22
+ expect(instance).to respond_to(:validate)
23
+ end
24
+ end
25
+
26
+ context 'ID token decoding' do
27
+ expected_error = 'ID token could not be decoded'
28
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new({})
29
+
30
+ it 'is expected to raise an error with a nil id_token' do
31
+ expect { instance.validate(nil) }.to raise_exception(expected_error)
32
+ end
33
+
34
+ it 'is expected to raise an error with an empty id_token' do
35
+ expect { instance.validate('') }.to raise_exception(expected_error)
36
+ end
37
+
38
+ it 'is expected to raise an error with an invalid format' do
39
+ expect { instance.validate('a.b') }.to raise_exception(expected_error)
40
+ expect { instance.validate('a.b.') }.to raise_exception(expected_error)
41
+ expect { instance.validate('a.b.c.d') }.to raise_exception(expected_error)
42
+ end
43
+
44
+ it 'is expected to raise an error with an invalid encoding' do
45
+ expect { instance.validate('a.b.c') }.to raise_exception(expected_error)
46
+ end
47
+ end
48
+
49
+ context 'algorithm verification' do
50
+ token = 'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTU4NzY3ODk2MX0.Hn38QVtN_mWN0c-jOa-Fqq69kXpbBp0THsvE-CQ47Ps'
51
+
52
+ it 'is expected to raise an error with an unsupported algorithm' do
53
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new({ algorithm: 'ES256' })
54
+
55
+ expect { instance.validate(token) }.to raise_exception('Signature algorithm of "ES256" is not supported')
56
+ end
57
+
58
+ it 'is expected to raise an error when the algorithm does not match the alg header value' do
59
+ algorithm = Auth0::Algorithm::HS256.secret(HMAC_SHARED_SECRET)
60
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new({ algorithm: algorithm })
61
+
62
+ expect { instance.validate(token) }.to raise_exception('Signature algorithm of "ES256" is not supported. Expected the ID token to be signed with "HS256"')
63
+ end
64
+ end
65
+
66
+ context 'HS256 signature verification' do
67
+ before :each do
68
+ algorithm = Auth0::Algorithm::HS256.secret(HMAC_SHARED_SECRET)
69
+ @instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ algorithm: algorithm }))
70
+ end
71
+
72
+ it 'is expected not to raise an error with a valid signature' do
73
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTU4NzY3ODk2MX0.Hn38QVtN_mWN0c-jOa-Fqq69kXpbBp0THsvE-CQ47Ps'
74
+
75
+ expect { @instance.validate(token) }.not_to raise_exception
76
+ end
77
+
78
+ it 'is expected to raise an error with an invalid signature' do
79
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTU4NzY3ODk2MX0.invalidsignature'
80
+
81
+ expect { @instance.validate(token) }.to raise_exception('Invalid ID token signature')
82
+ end
83
+ end
84
+
85
+ context 'RS256 signature verification' do
86
+ before :each do
87
+ stub_jwks
88
+ algorithm = Auth0::Algorithm::RS256.jwks_url(JWKS_URL)
89
+ @instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ algorithm: algorithm }))
90
+ end
91
+
92
+ after :each do
93
+ Auth0::Algorithm::RS256.remove_jwks
94
+ WebMock.reset!
95
+ end
96
+
97
+ it 'is expected not to raise an error with a valid signature' do
98
+ token = 'eyJhbGciOiJSUzI1NiIsImtpZCI6InRlc3Qta2V5LTEifQ.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTU4NzY3ODk2MX0.jE00ARUiAwrKEoAMwbioKYj4bUZjmg31V7McDtIPsJJ16rYcvI-e5mtSSMgCmAom6t-WA7dsSWCJUlBCW2nAMvyCZ-hj8HG9Z0RmQEiwig9Fk22avoX94zdx65TwAeDfn2uMRaX_ps3TJcn4nymUtMp8Lps_vMw15eJerKThlSO4KuLTrvDDdRaCRamAd7jxuzhiwOt0mB0TVD55b5itA02pGuyapbjQXvvLYEx8OgpyIaAkB9Ry25abgjev0bSw2kjFZckG3lv9QgvZM85m9l3Rbrc6msNPGfMDFWGyT3Tu2ObqnSEA-57hZeuCbFrOya3vUwgSlc66rfvZj2xpzg'
99
+
100
+ expect { @instance.validate(token) }.not_to raise_exception
101
+ end
102
+
103
+ it 'is expected to raise an error with an invalid signature' do
104
+ token = 'eyJhbGciOiJSUzI1NiIsImtpZCI6InRlc3Qta2V5LTEifQ.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTU4NzY3ODk2MX0.invalidsignature'
105
+
106
+ expect { @instance.validate(token) }.to raise_exception('Invalid ID token signature')
107
+ end
108
+
109
+ it 'is expected to raise an error when the public key cannot be found' do
110
+ token = 'eyJhbGciOiJSUzI1NiIsImtpZCI6InRlc3Qta2V5LTIifQ.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTU4NzY3ODk2MX0.r2ksgiiM8zGJ6byea_Fq_zWWEmUdOnwQLVdb5JzgdBv1GUQFp-4LNaRhcga4FIrbKgxaPeewGLTq2VqfjmNJUNfARcE3QEacQ_JEHkC6zKZIiqcu4msHl8X9HXyHxOPHMTTjYMjauPzET7UH_oLxF68DDDQqvKX9VqLsncpyC-KdTCFTLGlFSq6pxmYt6gwrF2Uo15Gzc6qe2I9-MTXCYd44VW1zQi6GhNJNKbXH6U3bf7nof0ot1PSjBXXuLgf6d3qumTStECCjIUmdBb6FiEX4SSRI4MgHWj4q0LyN28baRpYwYPhVnjzUxOP7OLjKiHs45ORBhuAWhrJnuR_uBQ'
111
+
112
+ expect { @instance.validate(token) }.to raise_exception('Could not find a public key for Key ID (kid) "test-key-2"')
113
+ end
114
+
115
+ it 'is expected to fetch the JWK set from the url if the public key cannot be found and the cache is not empty' do
116
+ token = 'eyJhbGciOiJSUzI1NiIsImtpZCI6InRlc3Qta2V5LTIifQ.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTU4NzY3ODk2MX0.r2ksgiiM8zGJ6byea_Fq_zWWEmUdOnwQLVdb5JzgdBv1GUQFp-4LNaRhcga4FIrbKgxaPeewGLTq2VqfjmNJUNfARcE3QEacQ_JEHkC6zKZIiqcu4msHl8X9HXyHxOPHMTTjYMjauPzET7UH_oLxF68DDDQqvKX9VqLsncpyC-KdTCFTLGlFSq6pxmYt6gwrF2Uo15Gzc6qe2I9-MTXCYd44VW1zQi6GhNJNKbXH6U3bf7nof0ot1PSjBXXuLgf6d3qumTStECCjIUmdBb6FiEX4SSRI4MgHWj4q0LyN28baRpYwYPhVnjzUxOP7OLjKiHs45ORBhuAWhrJnuR_uBQ'
117
+ Auth0::Algorithm::RS256.jwks_url(JWKS_URL).jwks
118
+ stub_jwks(JWKS_RESPONSE_2)
119
+ @instance.validate(token)
120
+
121
+ expect(a_request(:get, JWKS_URL)).to have_been_made.twice
122
+ end
123
+ end
124
+
125
+ context 'context validation' do
126
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTU4NzY3ODk2MX0.Hn38QVtN_mWN0c-jOa-Fqq69kXpbBp0THsvE-CQ47Ps'
127
+
128
+ it 'is expected to raise an error with a non-integer leeway' do
129
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ leeway: '1' }))
130
+
131
+ expect { instance.validate(token) }.to raise_exception('Must supply a valid leeway')
132
+ end
133
+
134
+ it 'is expected to raise an error with a negative leeway' do
135
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ leeway: -1 }))
136
+
137
+ expect { instance.validate(token) }.to raise_exception('Must supply a valid leeway')
138
+ end
139
+
140
+ it 'is expected to raise an error with an empty nonce' do
141
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ nonce: '' }))
142
+
143
+ expect { instance.validate(token) }.to raise_exception('Must supply a valid nonce')
144
+ end
145
+
146
+ it 'is expected to raise an error with an empty organization' do
147
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ organization: '' }))
148
+
149
+ expect { instance.validate(token) }.to raise_exception('Must supply a valid organization')
150
+ end
151
+
152
+ it 'is expected to raise an error with an empty issuer' do
153
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ issuer: '' }))
154
+
155
+ expect { instance.validate(token) }.to raise_exception('Must supply a valid issuer')
156
+ end
157
+
158
+ it 'is expected to raise an error with an empty audience' do
159
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ audience: '' }))
160
+
161
+ expect { instance.validate(token) }.to raise_exception('Must supply a valid audience')
162
+ end
163
+
164
+ it 'is expected to raise an error with a non-integer max_age' do
165
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ max_age: '1' }))
166
+
167
+ expect { instance.validate(token) }.to raise_exception('Must supply a valid max_age')
168
+ end
169
+
170
+ it 'is expected to raise an error with a negative max_age' do
171
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ max_age: -1 }))
172
+
173
+ expect { instance.validate(token) }.to raise_exception('Must supply a valid max_age')
174
+ end
175
+ end
176
+
177
+ context 'claims validation' do
178
+ before :all do
179
+ @instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT)
180
+ end
181
+
182
+ it 'is expected to raise an error with a missing iss' do
183
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTU4NzY3ODk2MX0.QL2B2tqJhlW9rc8HQ3PQKkjDufBeSvtRBtJmRPdQ5K8'
184
+
185
+ expect { @instance.validate(token) }.to raise_exception('Issuer (iss) claim must be a string present in the ID token')
186
+ end
187
+
188
+ it 'is expected to raise an error with a invalid iss' do
189
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzb21ldGhpbmctZWxzZSIsInN1YiI6ImF1dGgwfDEyMzQ1Njc4OSIsImF1ZCI6WyJ0b2tlbnMtdGVzdC0xMjMiLCJleHRlcm5hbC10ZXN0LTk5OSJdLCJleHAiOjE1ODc3NjUzNjEsImlhdCI6MTU4NzU5MjU2MSwibm9uY2UiOiJhMWIyYzNkNGU1IiwiYXpwIjoidG9rZW5zLXRlc3QtMTIzIiwiYXV0aF90aW1lIjoxNTg3Njc4OTYxfQ.AhMMouDlGMdxTYrY9Cn-p8svJ8ssKmsHeT6JNRVTh10'
190
+
191
+ expect { @instance.validate(token) }.to raise_exception("Issuer (iss) claim mismatch in the ID token; expected \"#{CONTEXT[:issuer]}\", found \"something-else\"")
192
+ end
193
+
194
+ it 'is expected to raise an error with a missing sub' do
195
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTU4NzY3ODk2MX0._4sUXtAZYpGrO3QaYArXnk2JivCqixa7hgHhH3w4SlY'
196
+
197
+ expect { @instance.validate(token) }.to raise_exception('Subject (sub) claim must be a string present in the ID token')
198
+ end
199
+
200
+ it 'is expected to raise an error with a missing aud' do
201
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJleHAiOjE1ODc3NjUzNjEsImlhdCI6MTU4NzU5MjU2MSwibm9uY2UiOiJhMWIyYzNkNGU1IiwiYXpwIjoidG9rZW5zLXRlc3QtMTIzIiwiYXV0aF90aW1lIjoxNTg3Njc4OTYxfQ.TlwnBmGUKe0SElSYKxPqsG1mujkK2t1CwDJGGiWRdXA'
202
+
203
+ expect { @instance.validate(token) }.to raise_exception('Audience (aud) claim must be a string or array of strings present in the ID token')
204
+ end
205
+
206
+ it 'is expected to raise an error with an invalid string aud' do
207
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOiJleHRlcm5hbC10ZXN0LTk5OSIsImV4cCI6MTU4Nzc2NTM2MSwiaWF0IjoxNTg3NTkyNTYxLCJub25jZSI6ImExYjJjM2Q0ZTUiLCJhenAiOiJ0b2tlbnMtdGVzdC0xMjMiLCJhdXRoX3RpbWUiOjE1ODc2Nzg5NjF9.-Tf5CIi2bZ51UdgqxFWQNXpJJmK5GgsetcVoVrQwHIA'
208
+
209
+ expect { @instance.validate(token) }.to raise_exception("Audience (aud) claim mismatch in the ID token; expected \"#{CONTEXT[:audience]}\", found \"external-test-999\"")
210
+ end
211
+
212
+ it 'is expected to raise an error with an invalid array aud' do
213
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsiZXh0ZXJuYWwtdGVzdC05OTgiLCJleHRlcm5hbC10ZXN0LTk5OSJdLCJleHAiOjE1ODc3NjUzNjEsImlhdCI6MTU4NzU5MjU2MSwibm9uY2UiOiJhMWIyYzNkNGU1IiwiYXpwIjoidG9rZW5zLXRlc3QtMTIzIiwiYXV0aF90aW1lIjoxNTg3Njc4OTYxfQ.Q1GRVL5g3RLQqG5sEV_cc8WW_oiZzFIAfzRfBdxMW2s'
214
+
215
+ expect { @instance.validate(token) }.to raise_exception("Audience (aud) claim mismatch in the ID token; expected \"#{CONTEXT[:audience]}\" but was not one of \"external-test-998, external-test-999\"")
216
+ end
217
+
218
+ it 'is expected to raise an error with a missing exp' do
219
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiaWF0IjoxNTg3NTkyNTYxLCJub25jZSI6ImExYjJjM2Q0ZTUiLCJhenAiOiJ0b2tlbnMtdGVzdC0xMjMiLCJhdXRoX3RpbWUiOjE1ODc2Nzg5NjF9.aoLiQX3sHsf1bEbc0axbjJ9qV6hhomtEzJq-FT8OGF0'
220
+
221
+ expect { @instance.validate(token) }.to raise_exception('Expiration Time (exp) claim must be a number present in the ID token')
222
+ end
223
+
224
+ it 'is expected to raise an error with a invalid exp' do
225
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NTkyNTYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTU4NzY3ODk2MX0.A8Pc0vlCG5Ufez7VIoRqXTYpJehalTEgGX9cR2xJLkU'
226
+ clock = CLOCK + LEEWAY + 1
227
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ clock: clock }))
228
+
229
+ expect { instance.validate(token) }.to raise_exception("Expiration Time (exp) claim mismatch in the ID token; current time \"#{clock}\" is after expiration time \"1587592621\"")
230
+ end
231
+
232
+ it 'is expected to raise an error with a missing iat' do
233
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJub25jZSI6ImExYjJjM2Q0ZTUiLCJhenAiOiJ0b2tlbnMtdGVzdC0xMjMiLCJhdXRoX3RpbWUiOjE1ODc2Nzg5NjF9.Jea6UVJsAK7Hnb494f_WIQCIbaLTnnCvMenSY1Y2toc'
234
+
235
+ expect { @instance.validate(token) }.to raise_exception('Issued At (iat) claim must be a number present in the ID token')
236
+ end
237
+
238
+ it 'is expected not to raise an error with a missing but not required nonce' do
239
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTU4NzY3ODk2MX0.-o5grnyODbBdRgzcrn7Sf9Hb6eOC0x_U2i3YjVgHN0U'
240
+
241
+ expect { @instance.validate(token) }.not_to raise_exception
242
+ end
243
+
244
+ it 'is expected to raise an error with a missing but required nonce' do
245
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTU4NzY3ODk2MX0.-o5grnyODbBdRgzcrn7Sf9Hb6eOC0x_U2i3YjVgHN0U'
246
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ nonce: 'a1b2c3d4e5' }))
247
+
248
+ expect { instance.validate(token) }.to raise_exception('Nonce (nonce) claim must be a string present in the ID token')
249
+ end
250
+
251
+ it 'is expected to raise an error with an invalid nonce' do
252
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiMDAwOTk5IiwiYXpwIjoidG9rZW5zLXRlc3QtMTIzIiwiYXV0aF90aW1lIjoxNTg3Njc4OTYxfQ.XqQPdFN4m5kmTUQQi_mAJu0LQOeUTS9lF2J_xWc_j-0'
253
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ nonce: 'a1b2c3d4e5' }))
254
+
255
+ expect { instance.validate(token) }.to raise_exception('Nonce (nonce) claim mismatch in the ID token; expected "a1b2c3d4e5", found "000999"')
256
+ end
257
+
258
+ it 'is expected to raise an error with a missing azp' do
259
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF1dGhfdGltZSI6MTU4NzY3ODk2MX0.LrgYkIbWrxMq6jvvkL1lxWL237ii1IBhtN2o_tDxFns'
260
+
261
+ expect { @instance.validate(token) }.to raise_exception('Authorized Party (azp) claim must be a string present in the ID token')
262
+ end
263
+
264
+ it 'is expected to raise an error with an invalid azp' do
265
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6ImV4dGVybmFsLXRlc3QtOTk5IiwiYXV0aF90aW1lIjoxNTg3Njc4OTYxfQ.3DX-LY3B4UngDML-9nv11Sv89ECJpRpOLeWnkF1vAFY'
266
+
267
+ expect { @instance.validate(token) }.to raise_exception("Authorized Party (azp) claim mismatch in the ID token; expected \"tokens-test-123\", found \"external-test-999\"")
268
+ end
269
+
270
+ it 'is expected to raise an error with a missing auth_time' do
271
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyJ9.JqUotnjHbGW0FcHz1s1YsRkce9Sbpsv2AEBDMpcUhp8'
272
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ max_age: 120 }))
273
+
274
+ expect { instance.validate(token) }.to raise_exception('Authentication Time (auth_time) claim must be a number present in the ID token when Max Age (max_age) is specified')
275
+ end
276
+
277
+ it 'is expected to raise an error with a invalid auth_time' do
278
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNTg3NzY1MzYxLCJpYXQiOjE1ODc1OTI1NjEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTU4NzU5MjU2MX0.B7eWHJPHjhOh0ALjIQi0ro6zVsqGIeHd0gpRZsv6Hg8'
279
+ max_age = 120
280
+ auth_time = CLOCK + LEEWAY + max_age
281
+ clock = auth_time + 1
282
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ max_age: max_age, clock: clock }))
283
+
284
+ expect { instance.validate(token) }.to raise_exception("Authentication Time (auth_time) claim in the ID token indicates that too much time has passed since the last end-user authentication. Current time \"#{clock}\" is after last auth at \"#{auth_time}\"")
285
+ end
286
+
287
+ it 'is expected not to raise an error when org_id exsist in the token, but not required' do
288
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNjE2NjE3ODgxLCJpYXQiOjE2MTY0NDUwODEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTYxNjUzMTQ4MSwib3JnX2lkIjoidGVzdE9yZyJ9.AOafUKUNgaxUXpSRYFCeJERcwrQZ4q2NZlutwGXnh9I'
289
+ expect { @instance.validate(token) }.not_to raise_exception
290
+ end
291
+
292
+ it 'is expected to raise an error with a missing but required organization' do
293
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNjE2NjE4MTg1LCJpYXQiOjE2MTY0NDUzODUsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTYxNjUzMTc4NX0.UMo5pmgceXO9lIKzbk7X0ZhE5DOe0IP2LfMKdUj03zQ'
294
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ organization: 'a1b2c3d4e5' }))
295
+
296
+ expect { instance.validate(token) }.to raise_exception('Organization Id (org_id) claim must be a string present in the ID token')
297
+ end
298
+
299
+ it 'is expected to raise an error with an invalid organization' do
300
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNjE2NjE3ODgxLCJpYXQiOjE2MTY0NDUwODEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTYxNjUzMTQ4MSwib3JnX2lkIjoidGVzdE9yZyJ9.AOafUKUNgaxUXpSRYFCeJERcwrQZ4q2NZlutwGXnh9I'
301
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ organization: 'a1b2c3d4e5' }))
302
+
303
+ expect { instance.validate(token) }.to raise_exception('Organization Id (org_id) claim value mismatch in the ID token; expected "a1b2c3d4e5", found "testOrg"')
304
+ end
305
+
306
+ it 'is expected to NOT raise an error with a valid organization' do
307
+ token = 'eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3Rva2Vucy10ZXN0LmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHwxMjM0NTY3ODkiLCJhdWQiOlsidG9rZW5zLXRlc3QtMTIzIiwiZXh0ZXJuYWwtdGVzdC05OTkiXSwiZXhwIjoxNjE2NjE3ODgxLCJpYXQiOjE2MTY0NDUwODEsIm5vbmNlIjoiYTFiMmMzZDRlNSIsImF6cCI6InRva2Vucy10ZXN0LTEyMyIsImF1dGhfdGltZSI6MTYxNjUzMTQ4MSwib3JnX2lkIjoidGVzdE9yZyJ9.AOafUKUNgaxUXpSRYFCeJERcwrQZ4q2NZlutwGXnh9I'
308
+ instance = Auth0::Mixins::Validation::IdTokenValidator.new(CONTEXT.merge({ organization: 'testOrg' }))
309
+
310
+ expect { instance.validate(token) }.not_to raise_exception
311
+ end
312
+ end
313
+ end
314
+
315
+ describe Auth0::Algorithm::HS256 do
316
+ context 'class' do
317
+ it 'is expected to respond to :secret' do
318
+ expect(Auth0::Algorithm::HS256).to respond_to(:secret)
319
+ end
320
+
321
+ it 'is expected not to respond to :new' do
322
+ expect(Auth0::Algorithm::HS256).not_to respond_to(:new)
323
+ end
324
+ end
325
+
326
+ context 'instance' do
327
+ it 'is expected to respond to :secret' do
328
+ instance = Auth0::Algorithm::HS256.secret('secret')
329
+
330
+ expect(instance).to respond_to(:secret)
331
+ end
332
+
333
+ it 'is expected to return the secret' do
334
+ instance = Auth0::Algorithm::HS256.secret('secret')
335
+
336
+ expect(instance.secret).to eq('secret')
337
+ end
338
+
339
+ it 'is expected to return the algorithm name' do
340
+ instance = Auth0::Algorithm::HS256.secret('secret')
341
+
342
+ expect(instance.name).to eq('HS256')
343
+ end
344
+ end
345
+
346
+ context 'parameters' do
347
+ expected_error = 'Must supply a valid secret'
348
+
349
+ it 'is expected to raise an error with a nil secret' do
350
+ expect { Auth0::Algorithm::HS256.secret(nil) }.to raise_exception(expected_error)
351
+ end
352
+
353
+ it 'is expected to raise an error with an empty secret' do
354
+ expect { Auth0::Algorithm::HS256.secret('') }.to raise_exception(expected_error)
355
+ end
356
+ end
357
+ end
358
+
359
+ describe Auth0::Algorithm::RS256 do
360
+ before :each do
361
+ stub_jwks
362
+ end
363
+
364
+ after :each do
365
+ Auth0::Algorithm::RS256.remove_jwks
366
+ WebMock.reset!
367
+ end
368
+
369
+ context 'class' do
370
+ it 'is expected to respond to :jwks_url' do
371
+ expect(Auth0::Algorithm::RS256).to respond_to(:jwks_url)
372
+ end
373
+
374
+ it 'is expected not to respond to :new' do
375
+ expect(Auth0::Algorithm::RS256).not_to respond_to(:new)
376
+ end
377
+ end
378
+
379
+ context 'instance' do
380
+ it 'is expected to respond to :jwks' do
381
+ instance = Auth0::Algorithm::RS256.jwks_url('jwks url')
382
+
383
+ expect(instance).to respond_to(:jwks)
384
+ end
385
+
386
+ it 'is expected to respond to :fetched_jwks?' do
387
+ instance = Auth0::Algorithm::RS256.jwks_url('jwks url')
388
+
389
+ expect(instance).to respond_to(:fetched_jwks?)
390
+ end
391
+
392
+ it 'is expected to return a jwks' do
393
+ instance = Auth0::Algorithm::RS256.jwks_url(JWKS_URL)
394
+
395
+ expect(instance.jwks).to have_key('keys') and contain_exactly(a_hash_including(kid: 'test-key-1'))
396
+ end
397
+
398
+ it 'is expected to return if the jwks was fetched from the url' do
399
+ instance = Auth0::Algorithm::RS256.jwks_url(JWKS_URL)
400
+ instance.jwks
401
+
402
+ expect(instance.fetched_jwks?).to eq(true)
403
+ end
404
+
405
+ it 'is expected to return if the jwks was fetched from the cache' do
406
+ Auth0::Algorithm::RS256.jwks_url(JWKS_URL).jwks
407
+ instance = Auth0::Algorithm::RS256.jwks_url(JWKS_URL)
408
+ instance.jwks
409
+
410
+ expect(instance.fetched_jwks?).to eq(false)
411
+ end
412
+
413
+ it 'is expected to return the algorithm name' do
414
+ instance = Auth0::Algorithm::RS256.jwks_url('jwks url')
415
+
416
+ expect(instance.name).to eq('RS256')
417
+ end
418
+ end
419
+
420
+ context 'parameters' do
421
+ it 'is expected to raise an error with a nil jwks_url' do
422
+ expect { Auth0::Algorithm::RS256.jwks_url(nil) }.to raise_exception('Must supply a valid jwks_url')
423
+ end
424
+
425
+ it 'is expected to raise an error with an empty jwks_url' do
426
+ expect { Auth0::Algorithm::RS256.jwks_url('') }.to raise_exception('Must supply a valid jwks_url')
427
+ end
428
+
429
+ it 'is expected to raise an error with a non-integer lifetime' do
430
+ expect { Auth0::Algorithm::RS256.jwks_url('jwks url', lifetime: '1') }.to raise_exception('Must supply a valid lifetime')
431
+ end
432
+
433
+ it 'is expected to raise an error with a negative lifetime' do
434
+ expect { Auth0::Algorithm::RS256.jwks_url('jwks url', lifetime: -1) }.to raise_exception('Must supply a valid lifetime')
435
+ end
436
+ end
437
+
438
+ context 'cache' do
439
+ it 'is expected to fetch the jwks from the url when the cache is empty' do
440
+ instance = Auth0::Algorithm::RS256.jwks_url(JWKS_URL)
441
+ instance.jwks
442
+
443
+ expect(a_request(:get, JWKS_URL)).to have_been_made.once
444
+ end
445
+
446
+ it 'is expected to fetch the jwks from the url when the cache is expired' do
447
+ instance = Auth0::Algorithm::RS256.jwks_url(JWKS_URL, lifetime: 0)
448
+ instance.jwks
449
+ instance.jwks
450
+
451
+ expect(a_request(:get, JWKS_URL)).to have_been_made.twice
452
+ end
453
+
454
+ it 'is not expected to fetch the jwks from the url when there is a value cached' do
455
+ instance = Auth0::Algorithm::RS256.jwks_url(JWKS_URL)
456
+ instance.jwks
457
+ instance.jwks
458
+
459
+ expect(a_request(:get, JWKS_URL)).to have_been_made.once
460
+ end
461
+
462
+ it 'is expected to forcibly fetch the jwks from the url' do
463
+ instance = Auth0::Algorithm::RS256.jwks_url(JWKS_URL)
464
+ instance.jwks
465
+ instance.jwks(force: true)
466
+
467
+ expect(a_request(:get, JWKS_URL)).to have_been_made.twice
468
+ end
469
+
470
+ it 'is expected to forcibly fetch the jwks from the url and cache it' do
471
+ instance = Auth0::Algorithm::RS256.jwks_url(JWKS_URL)
472
+ instance.jwks(force: true)
473
+ instance.jwks
474
+
475
+ expect(a_request(:get, JWKS_URL)).to have_been_made.once
476
+ end
477
+
478
+ it 'is expected to return the last cached value if the jwks could not be fetched' do
479
+ Auth0::Algorithm::RS256.jwks_url(JWKS_URL).jwks
480
+ stub_request(:get, JWKS_URL).to_return(body: 'invalid')
481
+ instance = Auth0::Algorithm::RS256.jwks_url(JWKS_URL)
482
+
483
+ expect(instance.jwks).to have_key('keys') and contain_exactly(a_hash_including(kid: 'test-key-1'))
484
+ end
485
+
486
+ it 'is expected to raise an error if the jwks could not be fetched and the cache is empty' do
487
+ stub_request(:get, JWKS_URL).to_return(body: 'invalid')
488
+ instance = Auth0::Algorithm::RS256.jwks_url(JWKS_URL)
489
+
490
+ expect { instance.jwks }.to raise_exception('Could not fetch the JWK set')
491
+ end
492
+ end
493
+ end
494
+ # rubocop:enable Metrics/BlockLength
495
+
496
+ def stub_jwks(stub = JWKS_RESPONSE_1)
497
+ stub_request(:get, JWKS_URL).to_return(body: stub.to_json)
498
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,25 +1,68 @@
1
- require 'dotenv'
1
+ require 'pry'
2
+ require 'rack/test'
3
+ require 'faker'
4
+ require 'json'
5
+ require 'auth0'
6
+
7
+ if RUBY_VERSION >= '2.7.2'
8
+ # NOTE: https://bugs.ruby-lang.org/issues/17000
9
+ Warning[:deprecated] = true
10
+ end
2
11
 
12
+ require 'simplecov'
13
+ SimpleCov.start
14
+
15
+ if ENV['CI'] == 'true'
16
+ require 'codecov'
17
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
18
+ end
19
+
20
+ require 'dotenv'
3
21
  Dotenv.load
4
22
 
5
- mode = ENV['MODE'] || 'unit'
23
+ require 'webmock/rspec'
24
+ WebMock.allow_net_connect!
25
+
26
+ require 'vcr'
27
+ VCR.configure do |config|
28
+ # Uncomment the line below to record new VCR cassettes.
29
+ # When this is commented out, VCR will reject all outbound HTTP calls.
30
+ config.allow_http_connections_when_no_cassette = true
31
+ config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
32
+ config.configure_rspec_metadata!
33
+ config.hook_into :webmock
34
+ config.filter_sensitive_data('CLIENT_SECRET') { ENV['CLIENT_SECRET'] }
35
+ config.filter_sensitive_data('API_TOKEN') { ENV['MASTER_JWT'] }
36
+
37
+ ENV['DOMAIN'] = 'auth0-sdk-tests.auth0.com'
38
+ ENV['CLIENT_ID'] = '2cnWuug6zaFX1j0ge1P99jAUn0F4XSuI'
39
+ end
6
40
 
7
41
  $LOAD_PATH.unshift File.expand_path('..', __FILE__)
8
42
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
9
43
 
10
- require 'rspec'
11
- require 'rack/test'
12
- require 'faker'
13
- require 'auth0'
14
-
15
- Dir['./lib/**/*.rb'].each { |f| require f }
44
+ Dir['./lib/*.rb'].each { |f| require f }
45
+ Dir['./lib/api/**/*.rb'].each { |f| require f }
16
46
  Dir['./spec/support/**/*.rb'].each { |f| require f }
17
47
  Dir['./spec/support/*.rb'].each { |f| require f }
18
48
 
49
+ require 'rspec'
50
+ RSpec.configure do |config|
51
+ config.filter_run focus: true
52
+ config.run_all_when_everything_filtered = true
53
+ config.include Credentials
54
+ end
55
+
56
+ def wait(time, increment = 5, elapsed_time = 0, &block)
57
+ yield
58
+ rescue RSpec::Expectations::ExpectationNotMetError => e
59
+ raise e if elapsed_time >= time
60
+ sleep increment
61
+ wait(time, increment, elapsed_time + increment, &block)
62
+ end
63
+
19
64
  def entity_suffix
20
- (ENV['TRAVIS_JOB_ID'] || 'local').delete('_')
65
+ 'rubytest'
21
66
  end
22
67
 
23
68
  puts "Entity suffix is #{entity_suffix}"
24
-
25
- require_relative "spec_helper_#{mode}"
@@ -1,23 +1,11 @@
1
1
  module Credentials
2
2
  module_function
3
-
4
- def v1_creds
5
- { client_id: ENV['CLIENT_ID'],
6
- client_secret: ENV['CLIENT_SECRET'],
7
- domain: ENV['DOMAIN'],
8
- api_version: 1 }
9
- end
10
-
11
- def v1_global_creds
12
- { client_id: ENV['GLOBAL_CLIENT_ID'],
13
- client_secret: ENV['GLOBAL_CLIENT_SECRET'],
14
- domain: ENV['DOMAIN'],
15
- api_version: 1 }
16
- end
17
-
18
3
  def v2_creds
19
- { client_id: ENV['CLIENT_ID'],
20
- token: ENV['MASTER_JWT'],
21
- domain: ENV['DOMAIN'] }
4
+ {
5
+ domain: ENV.fetch( 'DOMAIN', 'DOMAIN' ),
6
+ client_id: ENV.fetch( 'CLIENT_ID', 'CLIENT_ID' ),
7
+ client_secret: ENV.fetch( 'CLIENT_SECRET', 'TEST_CLIENT_SECRET' ),
8
+ token: ENV.fetch( 'MASTER_JWT', 'TEST_MASTER_JWT' )
9
+ }
22
10
  end
23
11
  end
@@ -1,12 +1,16 @@
1
1
  class DummyClass
2
- attr_reader :domain, :client_id, :client_secret
2
+ include Auth0::Mixins::Headers
3
+
4
+ attr_reader :domain, :client_id, :client_secret, :audience
3
5
 
4
6
  def initialize
5
7
  @domain = 'test.auth0.com'
6
- @client_id = 'NyW50o8Qt8I1VhMVlTlfVwWLGzBIPuxb'
8
+ @client_id = '__test_client_id__'
9
+ @client_secret = '__test_client_secret__'
10
+ @audience = "https://#{@domain}/api/v2/"
7
11
  end
8
12
 
9
- %i(get post put patch delete).each do |method|
13
+ %i(get post put patch delete delete_with_body).each do |method|
10
14
  define_method(method) do |_path, _body = {}|
11
15
  true
12
16
  end
@@ -1,4 +1,5 @@
1
1
  class DummyClassForProxy
2
2
  include Auth0::Mixins::HTTPProxy
3
+ include Auth0::Mixins::Headers
3
4
  @base_uri = 'http://auth0.com'
4
5
  end
@@ -1 +1 @@
1
- StubResponse = Struct.new(:body, :success?, :code)
1
+ StubResponse = Struct.new(:body, :success?, :code, :headers)