auth0 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +2 -1
  4. data/.rubocop_todo.yml +0 -2
  5. data/.travis.yml +4 -2
  6. data/CHANGELOG.md +40 -38
  7. data/DEPLOYMENT.md +5 -0
  8. data/Gemfile +1 -1
  9. data/README.md +20 -2
  10. data/Rakefile +1 -1
  11. data/auth0.gemspec +4 -3
  12. data/doc_config/templates/default/layout/html/footer.erb +1 -1
  13. data/examples/ruby-api/.gitignore +86 -0
  14. data/examples/ruby-api/Gemfile +8 -0
  15. data/examples/ruby-api/README.md +24 -0
  16. data/examples/ruby-api/config.ru +2 -0
  17. data/examples/ruby-api/main.rb +33 -0
  18. data/examples/ruby-on-rails-api/.gitignore +18 -0
  19. data/examples/ruby-on-rails-api/Gemfile +48 -0
  20. data/examples/ruby-on-rails-api/README.md +27 -0
  21. data/examples/ruby-on-rails-api/Rakefile +6 -0
  22. data/examples/ruby-on-rails-api/app/assets/images/.keep +0 -0
  23. data/examples/ruby-on-rails-api/app/assets/javascripts/application.js +16 -0
  24. data/examples/ruby-on-rails-api/app/assets/stylesheets/application.css +15 -0
  25. data/examples/ruby-on-rails-api/app/controllers/application_controller.rb +8 -0
  26. data/examples/ruby-on-rails-api/app/controllers/concerns/.keep +0 -0
  27. data/examples/ruby-on-rails-api/app/controllers/ping_controller.rb +6 -0
  28. data/examples/ruby-on-rails-api/app/controllers/secured_ping_controller.rb +11 -0
  29. data/examples/ruby-on-rails-api/app/helpers/application_helper.rb +3 -0
  30. data/examples/ruby-on-rails-api/app/mailers/.keep +0 -0
  31. data/examples/ruby-on-rails-api/app/models/.keep +0 -0
  32. data/examples/ruby-on-rails-api/app/models/concerns/.keep +0 -0
  33. data/examples/ruby-on-rails-api/app/views/layouts/application.html.erb +14 -0
  34. data/examples/ruby-on-rails-api/bin/bundle +3 -0
  35. data/examples/ruby-on-rails-api/bin/rails +4 -0
  36. data/examples/ruby-on-rails-api/bin/rake +4 -0
  37. data/examples/ruby-on-rails-api/bin/setup +29 -0
  38. data/examples/ruby-on-rails-api/config.ru +4 -0
  39. data/examples/ruby-on-rails-api/config/application.rb +23 -0
  40. data/examples/ruby-on-rails-api/config/boot.rb +4 -0
  41. data/examples/ruby-on-rails-api/config/database.yml +27 -0
  42. data/examples/ruby-on-rails-api/config/environment.rb +5 -0
  43. data/examples/ruby-on-rails-api/config/environments/development.rb +37 -0
  44. data/examples/ruby-on-rails-api/config/environments/production.rb +83 -0
  45. data/examples/ruby-on-rails-api/config/environments/test.rb +41 -0
  46. data/examples/ruby-on-rails-api/config/initializers/backtrace_silencers.rb +7 -0
  47. data/examples/ruby-on-rails-api/config/initializers/cookies_serializer.rb +3 -0
  48. data/examples/ruby-on-rails-api/config/initializers/dotenv.rb +4 -0
  49. data/examples/ruby-on-rails-api/config/initializers/filter_parameter_logging.rb +4 -0
  50. data/examples/ruby-on-rails-api/config/initializers/inflections.rb +16 -0
  51. data/examples/ruby-on-rails-api/config/initializers/knock.rb +53 -0
  52. data/examples/ruby-on-rails-api/config/initializers/mime_types.rb +4 -0
  53. data/examples/ruby-on-rails-api/config/initializers/session_store.rb +3 -0
  54. data/examples/ruby-on-rails-api/config/initializers/wrap_parameters.rb +14 -0
  55. data/examples/ruby-on-rails-api/config/locales/en.yml +23 -0
  56. data/examples/ruby-on-rails-api/config/routes.rb +58 -0
  57. data/examples/ruby-on-rails-api/config/secrets.yml +28 -0
  58. data/examples/ruby-on-rails-api/db/schema.rb +15 -0
  59. data/examples/ruby-on-rails-api/db/seeds.rb +7 -0
  60. data/examples/ruby-on-rails-api/lib/assets/.keep +0 -0
  61. data/examples/ruby-on-rails-api/lib/tasks/.keep +0 -0
  62. data/examples/ruby-on-rails-api/log/.keep +0 -0
  63. data/examples/ruby-on-rails-api/public/404.html +67 -0
  64. data/examples/ruby-on-rails-api/public/422.html +67 -0
  65. data/examples/ruby-on-rails-api/public/500.html +66 -0
  66. data/examples/ruby-on-rails-api/public/favicon.ico +0 -0
  67. data/examples/ruby-on-rails-api/public/robots.txt +5 -0
  68. data/examples/ruby-on-rails-api/test/controllers/.keep +0 -0
  69. data/examples/ruby-on-rails-api/test/fixtures/.keep +0 -0
  70. data/examples/ruby-on-rails-api/test/helpers/.keep +0 -0
  71. data/examples/ruby-on-rails-api/test/integration/.keep +0 -0
  72. data/examples/ruby-on-rails-api/test/mailers/.keep +0 -0
  73. data/examples/ruby-on-rails-api/test/models/.keep +0 -0
  74. data/examples/ruby-on-rails-api/test/ping_controller_test.rb +8 -0
  75. data/examples/ruby-on-rails-api/test/secured_ping_controller_test.rb +26 -0
  76. data/examples/ruby-on-rails-api/test/test_helper.rb +16 -0
  77. data/lib/auth0/api/authentication_endpoints.rb +59 -30
  78. data/lib/auth0/api/v1/clients.rb +1 -1
  79. data/lib/auth0/api/v1/connections.rb +4 -3
  80. data/lib/auth0/api/v1/logs.rb +1 -1
  81. data/lib/auth0/api/v1/rules.rb +1 -1
  82. data/lib/auth0/api/v1/users.rb +5 -5
  83. data/lib/auth0/api/v2.rb +10 -0
  84. data/lib/auth0/api/v2/blacklists.rb +1 -1
  85. data/lib/auth0/api/v2/client_grants.rb +57 -0
  86. data/lib/auth0/api/v2/clients.rb +14 -14
  87. data/lib/auth0/api/v2/connections.rb +19 -20
  88. data/lib/auth0/api/v2/device_credentials.rb +76 -0
  89. data/lib/auth0/api/v2/emails.rb +5 -7
  90. data/lib/auth0/api/v2/jobs.rb +15 -12
  91. data/lib/auth0/api/v2/logs.rb +65 -0
  92. data/lib/auth0/api/v2/resource_servers.rb +61 -0
  93. data/lib/auth0/api/v2/rules.rb +21 -20
  94. data/lib/auth0/api/v2/stats.rb +2 -2
  95. data/lib/auth0/api/v2/tenants.rb +6 -4
  96. data/lib/auth0/api/v2/tickets.rb +13 -14
  97. data/lib/auth0/api/v2/user_blocks.rb +62 -0
  98. data/lib/auth0/api/v2/users.rb +63 -32
  99. data/lib/auth0/client.rb +0 -2
  100. data/lib/auth0/mixins.rb +4 -3
  101. data/lib/auth0/mixins/httpproxy.rb +55 -0
  102. data/lib/auth0/mixins/initializer.rb +27 -10
  103. data/lib/auth0/version.rb +1 -1
  104. data/spec/integration/lib/auth0/api/api_authentication_spec.rb +118 -0
  105. data/spec/integration/lib/auth0/api/v2/api_blacklist_spec.rb +1 -1
  106. data/spec/integration/lib/auth0/api/v2/api_client_grants_spec.rb +53 -0
  107. data/spec/integration/lib/auth0/api/v2/api_clients_spec.rb +5 -2
  108. data/spec/integration/lib/auth0/api/v2/api_connections_spec.rb +8 -5
  109. data/spec/integration/lib/auth0/api/v2/api_device_credentials_spec.rb +67 -0
  110. data/spec/integration/lib/auth0/api/v2/api_email_spec.rb +15 -8
  111. data/spec/integration/lib/auth0/api/v2/api_jobs_spec.rb +11 -9
  112. data/spec/integration/lib/auth0/api/v2/api_logs_spec.rb +69 -0
  113. data/spec/integration/lib/auth0/api/v2/api_resource_servers_spec.rb +47 -0
  114. data/spec/integration/lib/auth0/api/v2/api_rules_spec.rb +2 -1
  115. data/spec/integration/lib/auth0/api/v2/api_tickets_spec.rb +2 -2
  116. data/spec/integration/lib/auth0/api/v2/api_user_blocks_spec.rb +73 -0
  117. data/spec/integration/lib/auth0/api/v2/api_users_spec.rb +32 -5
  118. data/spec/integration/lib/auth0/auth0_client_spec.rb +14 -11
  119. data/spec/lib/auth0/api/authentication_endpoints_spec.rb +116 -56
  120. data/spec/lib/auth0/api/v1/connections_spec.rb +2 -4
  121. data/spec/lib/auth0/api/v1/rules_spec.rb +2 -1
  122. data/spec/lib/auth0/api/v1/users_spec.rb +17 -9
  123. data/spec/lib/auth0/api/v2/client_grants_spec.rb +44 -0
  124. data/spec/lib/auth0/api/v2/connections_spec.rb +2 -1
  125. data/spec/lib/auth0/api/v2/device_credentials_spec.rb +73 -0
  126. data/spec/lib/auth0/api/v2/jobs_spec.rb +3 -2
  127. data/spec/lib/auth0/api/v2/logs_spec.rb +48 -0
  128. data/spec/lib/auth0/api/v2/resource_servers_spec.rb +63 -0
  129. data/spec/lib/auth0/api/v2/rules_spec.rb +8 -4
  130. data/spec/lib/auth0/api/v2/tenants_spec.rb +2 -1
  131. data/spec/lib/auth0/api/v2/tickets_spec.rb +4 -7
  132. data/spec/lib/auth0/api/v2/user_blocks_spec.rb +52 -0
  133. data/spec/lib/auth0/api/v2/users_spec.rb +39 -6
  134. data/spec/lib/auth0/client_spec.rb +8 -5
  135. data/spec/lib/auth0/mixins/httpproxy_spec.rb +225 -0
  136. data/spec/lib/auth0/mixins/initializer_spec.rb +1 -1
  137. data/spec/spec_helper_full.rb +12 -3
  138. data/spec/spec_helper_unit.rb +2 -2
  139. data/spec/support/credentials.rb +6 -4
  140. data/spec/support/dummy_class.rb +2 -1
  141. data/spec/support/dummy_class_for_proxy.rb +2 -2
  142. data/spec/support/dummy_class_for_restclient.rb +2 -0
  143. metadata +117 -9
  144. data/lib/auth0/mixins/httparty_proxy.rb +0 -38
  145. data/spec/lib/auth0/mixins/httparty_proxy_spec.rb +0 -148
@@ -8,7 +8,7 @@ module Auth0
8
8
  # Retrieves a list of all client applications. Accepts a list of fields to include or exclude.
9
9
  # @see https://auth0.com/docs/api/v2#!/clients/get_clients
10
10
  # @param fields [string] A comma separated list of fields to include or exclude from the result.
11
- # @param include_fields [boolean] if the fields specified are to be included in the result, false otherwise
11
+ # @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
12
12
  #
13
13
  # @return [json] Returns the clients applications.
14
14
  def clients(fields: nil, include_fields: nil)
@@ -19,15 +19,15 @@ module Auth0
19
19
  }
20
20
  get(clients_path, request_params)
21
21
  end
22
- alias_method :get_clients, :clients
22
+ alias get_clients clients
23
23
 
24
24
  # Creates a new client application.
25
25
  # @see https://auth0.com/docs/api/v2#!/clients/post_clients
26
- # @param name [string] The name of the client. Must contain at least one character. Does not allow '<' or '>'
26
+ # @param name [string] The name of the client. Must contain at least one character. Does not allow '<' or '>'.
27
27
  # @param options [hash] The Hash options used to define the client's properties.
28
- # @return [json] Returns the created client application.
28
+ # @return [json] Returns the created client application.
29
29
  def create_client(name, options = {})
30
- fail Auth0::MissingParameter, 'Must specify a valid client name' if name.to_s.empty?
30
+ raise Auth0::MissingParameter, 'Must specify a valid client name' if name.to_s.empty?
31
31
  request_params = Hash[options.map { |(k, v)| [k.to_sym, v] }]
32
32
  request_params[:name] = name
33
33
  post(clients_path, request_params)
@@ -35,12 +35,12 @@ module Auth0
35
35
 
36
36
  # Retrieves a client by its id.
37
37
  # @see https://auth0.com/docs/api/v2#!/Clients/get_clients_by_id
38
- # @param client_id [string] The id of the client to retrieve
38
+ # @param client_id [string] The id of the client to retrieve.
39
39
  # @param fields [string] A comma separated list of fields to include or exclude from the result.
40
- # @param include_fields [boolean] If the fields specified are to be included in the result, false otherwise
41
- # @return [json] Returns the requested client application.
40
+ # @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
41
+ # @return [json] Returns the requested client application.
42
42
  def client(client_id, fields: nil, include_fields: nil)
43
- fail Auth0::MissingClientId, 'Must specify a client id' if client_id.to_s.empty?
43
+ raise Auth0::MissingClientId, 'Must specify a client id' if client_id.to_s.empty?
44
44
  include_fields = true if !fields.nil? && include_fields.nil?
45
45
  request_params = {
46
46
  fields: fields,
@@ -52,20 +52,20 @@ module Auth0
52
52
 
53
53
  # Deletes a client and all its related assets (like rules, connections, etc) given its id.
54
54
  # @see https://auth0.com/docs/api/v2#!/Clients/delete_clients_by_id
55
- # @param client_id [string] The id of the client to delete
55
+ # @param client_id [string] The id of the client to delete.
56
56
  def delete_client(client_id)
57
- fail Auth0::MissingClientId, 'Must specify a client id' if client_id.to_s.empty?
57
+ raise Auth0::MissingClientId, 'Must specify a client id' if client_id.to_s.empty?
58
58
  path = "#{clients_path}/#{client_id}"
59
59
  delete(path)
60
60
  end
61
61
 
62
62
  # Updates a client.
63
63
  # @see https://auth0.com/docs/api/v2#!/Clients/patch_clients_by_id
64
- # @param client_id [string] The id of the client to update
64
+ # @param client_id [string] The id of the client to update.
65
65
  # @param options [hash] The Hash options used to define the client's properties.
66
66
  def patch_client(client_id, options)
67
- fail Auth0::MissingClientId, 'Must specify a client id' if client_id.to_s.empty?
68
- fail Auth0::MissingParameter, 'Must specify a valid body' if options.to_s.empty?
67
+ raise Auth0::MissingClientId, 'Must specify a client id' if client_id.to_s.empty?
68
+ raise Auth0::MissingParameter, 'Must specify a valid body' if options.to_s.empty?
69
69
  path = "#{clients_path}/#{client_id}"
70
70
  patch(path, options)
71
71
  end
@@ -8,9 +8,10 @@ module Auth0
8
8
  # Retrieves every connection matching the specified strategy. All connections are retrieved if no strategy is
9
9
  # being specified. Accepts a list of fields to include or exclude in the resulting list of connection objects.
10
10
  # @see https://auth0.com/docs/api/v2#!/Connections/get_connections
11
- # @param strategy [string] Provide a type of strategy to only retrieve connections with that strategy
11
+ # @param strategy [string] Provide a type of strategy to only retrieve connections with that strategy (e.g. 'ad',
12
+ # 'facebook', 'twitter').
12
13
  # @param fields [string] A comma separated list of fields to include or exclude from the result.
13
- # @param include_fields [boolean] if the fields specified are to be included in the result, false otherwise.
14
+ # @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
14
15
  #
15
16
  # @return [json] Returns the existing connections matching the strategy.
16
17
  def connections(strategy: nil, fields: nil, include_fields: true)
@@ -21,28 +22,28 @@ module Auth0
21
22
  }
22
23
  get(connections_path, request_params)
23
24
  end
24
- alias_method :get_connections, :connections
25
+ alias get_connections connections
25
26
 
26
27
  # Creates a new connection according to the JSON object received in body.
27
28
  # @see https://auth0.com/docs/api/v2#!/Connections/post_connections
28
29
  # @param body [hash] The Hash options used to define the conecctions's properties.
29
30
  #
30
- # @return [json] Returns the created connection.
31
+ # @return [json] Returns the created connection.
31
32
  def create_connection(body)
32
- fail Auth0::InvalidParameter, 'Must specify a body to create a connection' if body.to_s.empty?
33
+ raise Auth0::InvalidParameter, 'Must specify a body to create a connection' if body.to_s.empty?
33
34
  request_params = body
34
35
  post(connections_path, request_params)
35
36
  end
36
37
 
37
38
  # Retrieves a connection by its id.
38
39
  # @see https://auth0.com/docs/api/v2#!/Connections/get_connections_by_id
39
- # @param connection_id [string] The id of the connection to retrieve
40
+ # @param connection_id [string] The id of the connection to retrieve.
40
41
  # @param fields [string] A comma separated list of fields to include or exclude from the result.
41
- # @param include_fields [boolean] if the fields specified are to be included in the result, false otherwise
42
+ # @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
42
43
  #
43
- # @return [json] Returns the matching connection
44
+ # @return [json] Returns the matching connection.
44
45
  def connection(connection_id, fields: nil, include_fields: true)
45
- fail Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
46
+ raise Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
46
47
  path = "#{connections_path}/#{connection_id}"
47
48
  request_params = {
48
49
  fields: fields,
@@ -53,9 +54,9 @@ module Auth0
53
54
 
54
55
  # Deletes a connection and all its users.
55
56
  # @see https://auth0.com/docs/api/v2#!/Connections/delete_connections_by_id
56
- # @param connection_id [string] The id of the connection to delete
57
+ # @param connection_id [string] The id of the connection to delete.
57
58
  def delete_connection(connection_id)
58
- fail Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
59
+ raise Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
59
60
  path = "#{connections_path}/#{connection_id}"
60
61
  delete(path)
61
62
  end
@@ -63,25 +64,23 @@ module Auth0
63
64
  # Deletes a specified connection user by its email (currently only database connections are supported and you
64
65
  # cannot delete all users from specific connection).
65
66
  # @see https://auth0.com/docs/api/v2#!/Connections/delete_users
66
- # @param connection_id [string] The id of the connection
67
- # @param user_email [string] The email of the user to delete
68
- #
69
- # @return [json] Returns the updated connection.
67
+ # @param connection_id [string] The id of the connection.
68
+ # @param user_email [string] The email of the user to delete.
70
69
  def delete_connection_user(connection_id, user_email)
71
- fail Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
72
- fail Auth0::InvalidParameter, 'Must supply a valid user email' if user_email.to_s.empty?
70
+ raise Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
71
+ raise Auth0::InvalidParameter, 'Must supply a valid user email' if user_email.to_s.empty?
73
72
  path = "#{connections_path}/#{connection_id}/users?email=#{user_email}"
74
73
  delete(path)
75
74
  end
76
75
 
77
76
  # Updates a connection. Updates the fields specified in the body parameter.
78
77
  # @see https://auth0.com/docs/api/v2#!/Connections/patch_connections_by_id
79
- # @param connection_id [string] The id of the connection to delete
78
+ # @param connection_id [string] The id of the connection to delete.
80
79
  # @param body [hash] The Hash options used to update the conecctions's properties.
81
80
  #
82
- # @return [json] Returns the updated connection.
81
+ # @return [json] Returns the updated connection.
83
82
  def update_connection(connection_id, body)
84
- fail Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
83
+ raise Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
85
84
  path = "#{connections_path}/#{connection_id}"
86
85
  patch(path, body)
87
86
  end
@@ -0,0 +1,76 @@
1
+ module Auth0
2
+ module Api
3
+ module V2
4
+ # Methods to use the device crenditials endpoints
5
+ module DeviceCredentials
6
+ attr_reader :device_credentials_path
7
+
8
+ # Retrieves log entries that match the specified search criteria.
9
+ # @see https://auth0.com/docs/api/v2#!/device_credentials/get_device_credentials
10
+ # @param fields [string] A comma separated list of fields to include or exclude from the result.
11
+ # @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
12
+ # @param user_id [string] The user_id of the devices to retrieve.
13
+ # @param client_id [string] The client_id of the devices to retrieve.
14
+ # @param type [string] The type of credentials. Possible values: 'public_key' or 'refresh_token'.
15
+ #
16
+ # @return [json] Returns the list of existing devices for the specified client_id.
17
+ # rubocop:disable Metrics/AbcSize
18
+ def device_credentials(client_id, options = {})
19
+ request_params = {
20
+ fields: options.fetch(:fields, nil),
21
+ include_fields: options.fetch(:include_fields, nil),
22
+ user_id: options.fetch(:user_id, nil),
23
+ client_id: client_id,
24
+ type: options.fetch(:type, nil)
25
+ }
26
+ raise Auth0::InvalidParameter, 'Must supply a valid client_id' if client_id.to_s.empty?
27
+ if !request_params[:type].nil? && !%w(public_key refresh_token).include?(request_params[:type])
28
+ raise Auth0::InvalidParameter, 'Type must be one of \'public_key\', \'refresh_token\''
29
+ end
30
+ get(device_credentials_path, request_params)
31
+ end
32
+ alias list_device_credentials device_credentials
33
+
34
+ # Creates a new device public key.
35
+ # @see https://auth0.com/docs/api/v2#!/device_credentials/post_device_credentials
36
+ # @param device_name [string] The device's name, a value that must be easily recognized by the device's owner.
37
+ # @param value [string] A base64 encoded string with the value of the credential.
38
+ # @param device_id [string] A unique identifier for the device.
39
+ # @param client_id [string] The client_id of the client for which the credential will be created.
40
+ #
41
+ # @return [json] Returns the created public key.
42
+ def create_device_credential(device_name, value, device_id, client_id)
43
+ raise Auth0::InvalidParameter, 'Must supply a valid device_name' if device_name.to_s.empty?
44
+ raise Auth0::InvalidParameter, 'Must supply a valid value' if value.to_s.empty?
45
+ raise Auth0::InvalidParameter, 'Must supply a valid device_id' if device_id.to_s.empty?
46
+ raise Auth0::InvalidParameter, 'Must supply a valid client_id' if client_id.to_s.empty?
47
+ request_params = {
48
+ device_name: device_name,
49
+ type: 'public_key',
50
+ value: value,
51
+ device_id: device_id,
52
+ client_id: client_id
53
+ }
54
+ post(device_credentials_path, request_params)
55
+ end
56
+ alias create_device_public_key create_device_credential
57
+
58
+ # Deletes a single device credential given its id.
59
+ # @see https://auth0.com/docs/api/v2#!/device_credentials/delete_device_credentials_by_id
60
+ # @param id [string] The id of the credential to delete.
61
+ def delete_device_credential(id)
62
+ raise Auth0::InvalidParameter, 'Must supply a valid id' if id.to_s.empty?
63
+ path = "#{device_credentials_path}/#{id}"
64
+ delete(path)
65
+ end
66
+
67
+ private
68
+
69
+ # Device Credentials API path
70
+ def device_credentials_path
71
+ @device_credentials_path ||= '/api/v2/device-credentials'
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -8,7 +8,7 @@ module Auth0
8
8
  # Get all the email providers.
9
9
  # @see https://auth0.com/docs/api/v2#!/Emails/get_provider
10
10
  # @param fields [string] A comma separated list of fields to include or exclude from the result.
11
- # @param include_fields [boolean] if the fields specified are to be included in the result, false otherwise.
11
+ # @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
12
12
  #
13
13
  # @return [json] Returns the existing email providers.
14
14
  def get_provider(fields: nil, include_fields: nil)
@@ -21,11 +21,9 @@ module Auth0
21
21
 
22
22
  # Configure a new email provider.
23
23
  # @see https://auth0.com/docs/api/v2#!/Emails/post_provider
24
- # @param body [hash] The Hash options used to spcify the email provider's properties.
25
- #
26
- # @return [json] Returns the created email provider.
24
+ # @param body [hash] The Hash options used to specify the email provider's properties.
27
25
  def configure_provider(body)
28
- fail Auth0::InvalidParameter, 'Must supply a valid body to create an email provider' if body.to_s.empty?
26
+ raise Auth0::InvalidParameter, 'Must supply a valid body to create an email provider' if body.to_s.empty?
29
27
  post(email_path, body)
30
28
  end
31
29
 
@@ -39,11 +37,11 @@ module Auth0
39
37
 
40
38
  # Updates the configured email provider.
41
39
  # @see https://auth0.com/docs/api/v2#!/Emails/patch_provider
42
- # @param body [hash] The Hash options used to spcify the email provider's properties.
40
+ # @param body [hash] The Hash options used to specify the email provider's properties.
43
41
  #
44
42
  # @return [json] Returns the updated email provider.
45
43
  def update_provider(body)
46
- fail Auth0::InvalidParameter, 'Must supply a valid body to update an email provider' if body.to_s.empty?
44
+ raise Auth0::InvalidParameter, 'Must supply a valid body to update an email provider' if body.to_s.empty?
47
45
  patch(email_path, body)
48
46
  end
49
47
 
@@ -7,11 +7,11 @@ module Auth0
7
7
 
8
8
  # Retrieves a job. Useful to check its status.
9
9
  # @see https://auth0.com/docs/api/v2#!/Jobs/get_jobs_by_job_id
10
- # @param job_id [string] The id of the job
10
+ # @param job_id [string] The id of the job.
11
11
  #
12
- # @return [json] the job status and properties
12
+ # @return [json] Returns the job status and properties.
13
13
  def get_job(job_id)
14
- fail Auth0::InvalidParameter, 'Must specify a job id' if job_id.to_s.empty?
14
+ raise Auth0::InvalidParameter, 'Must specify a job id' if job_id.to_s.empty?
15
15
  path = "#{jobs_path}/#{job_id}"
16
16
  get(path)
17
17
  end
@@ -19,13 +19,13 @@ module Auth0
19
19
  # Imports users to a connection from a file using a long running job.
20
20
  # Important: The documentation for the file format is at https://docs.auth0.com/bulk-import.
21
21
  # @see https://auth0.com/docs/api/v2#!/Jobs/post_users_imports
22
- # @param users_file [file] A file containing the users to import
23
- # @param connection_id [string] The connection id of the connection to which users will be inserted
22
+ # @param users_file [file] A file containing the users to import.
23
+ # @param connection_id [string] The connection id of the connection to which users will be inserted.
24
24
  #
25
- # @return [json] the job status and properties
25
+ # @return [json] Returns the job status and properties.
26
26
  def import_users(users_file, connection_id)
27
- fail Auth0::InvalidParameter, 'Must specify a valid file' if users_file.to_s.empty?
28
- fail Auth0::InvalidParameter, 'Must specify a connection_id' if connection_id.to_s.empty?
27
+ raise Auth0::InvalidParameter, 'Must specify a valid file' if users_file.to_s.empty?
28
+ raise Auth0::InvalidParameter, 'Must specify a connection_id' if connection_id.to_s.empty?
29
29
  request_params = {
30
30
  users: users_file,
31
31
  connection_id: connection_id
@@ -36,13 +36,16 @@ module Auth0
36
36
 
37
37
  # Send an email to the specified user that asks them to click a link to verify their email address.
38
38
  # @see https://auth0.com/docs/api/v2#!/Jobs/post_verification_email
39
- # @param user_id [string] The user_id of the user to whom the email will be sent
39
+ # @param user_id [string] The user_id of the user to whom the email will be sent.
40
40
  #
41
- # @return [json] the job status and properties
41
+ # @return [json] Returns the job status and properties.
42
42
  def send_verification_email(user_id)
43
- fail Auth0::InvalidParameter, 'Must specify a user id' if user_id.to_s.empty?
43
+ raise Auth0::InvalidParameter, 'Must specify a user id' if user_id.to_s.empty?
44
+ request_params = {
45
+ user_id: user_id
46
+ }
44
47
  path = "#{jobs_path}/verification-email"
45
- post(path, user_id)
48
+ post(path, request_params)
46
49
  end
47
50
 
48
51
  private
@@ -0,0 +1,65 @@
1
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
2
+ module Auth0
3
+ module Api
4
+ module V2
5
+ # Methods to use the logs endpoints
6
+ module Logs
7
+ attr_reader :logs_path
8
+
9
+ # Retrieves log entries that match the specified search criteria.
10
+ # @see https://auth0.com/docs/api/v2#!/Logs/get_logs
11
+ # @param q [string] Query in Lucene query string syntax.
12
+ # @param page [integer] The page number. Zero based.
13
+ # @param per_page [integer] The amount of entries per page. Default: 50. Max value: 100.
14
+ # @param sort [string] The field to use for sorting. 1 == ascending and -1 == descending.
15
+ # @param fields [string] A comma separated list of fields to include or exclude from the result.
16
+ # @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
17
+ # @param include_totals [string] True if a query summary must be included in the result, false otherwise.
18
+ # @param from [string] Log Event Id to start retrieving logs. You can limit the amount of logs using the take
19
+ # parameter.
20
+ # @param take [integer] The total amount of entries to retrieve when using the from parameter.
21
+ # Default: 50. Max value: 100.
22
+ #
23
+ # @return [json] Returns the list of existing log entries.
24
+ def logs(options = {})
25
+ request_params = {
26
+ q: options.fetch(:q, nil),
27
+ page: options.fetch(:page, nil),
28
+ per_page: options.fetch(:per_page, nil),
29
+ sort: options.fetch(:sort, nil),
30
+ fields: options.fetch(:fields, nil),
31
+ include_fields: options.fetch(:include_fields, nil),
32
+ include_totals: options.fetch(:include_totals, nil),
33
+ from: options.fetch(:from, nil),
34
+ take: options.fetch(:take, nil)
35
+ }
36
+ if request_params[:take].to_i > 100
37
+ raise Auth0::InvalidParameter, 'The total amount of entries to retrieve should be less than 100'
38
+ end
39
+ if request_params[:per_page].to_i > 100
40
+ raise Auth0::InvalidParameter, 'The total amount of entries per page should be less than 100'
41
+ end
42
+ get(logs_path, request_params)
43
+ end
44
+ alias get_logs logs
45
+
46
+ # Retrieves log entries that match the specified search criteria.
47
+ # @see https://auth0.com/docs/api/v2#!/Logs/get_logs_by_id
48
+ # @param id [string] The log_id of the log to retrieve.
49
+ #
50
+ # @return [json] Returns the log with the given id if exists.
51
+ def log(log_id)
52
+ raise Auth0::MissingParameter, 'Must supply a valid log_id' if log_id.to_s.empty?
53
+ path = "#{logs_path}/#{log_id}"
54
+ get(path)
55
+ end
56
+ alias get_logs_by_id log
57
+
58
+ # Logs API path
59
+ def logs_path
60
+ @logs_path ||= '/api/v2/logs'
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,61 @@
1
+ module Auth0
2
+ module Api
3
+ module V2
4
+ # Methods to use the resource servers endpoints
5
+ module ResourceServers
6
+ attr_reader :resource_servers_path
7
+
8
+ # Retrieves a resource server by its ID.
9
+ # @see https://auth0.com/docs/api/management/v2#!/Resource_Servers/get_resource_servers_by_id
10
+ # @param resource_server_id [string] The id of the resource server to retrieve.
11
+ #
12
+ # @return [json] Returns the resource server.
13
+ def resource_server(resource_server_id)
14
+ raise Auth0::InvalidParameter, 'Must supply a valid resource server id' if resource_server_id.to_s.empty?
15
+ path = "#{resource_servers_path}/#{resource_server_id}"
16
+ get(path)
17
+ end
18
+
19
+ alias get_resource_server resource_server
20
+
21
+ # Creates a new resource server according to the JSON object received in body.
22
+ # @see https://auth0.com/docs/api/management/v2#!/Resource_Servers/post_resource_servers
23
+ # @param identifier [string] The identifier of the resource server.
24
+ # @param name [string] The name of the resource server. Must contain at least one character.
25
+ # Does not allow '<' or '>'.
26
+ # @param signing_alg [string] The algorithm used to sign tokens.
27
+ # @param signing_secret [string] The secret used to sign tokens when using symmetric algorithms.
28
+ # @param token_lifetime [integer] The amount of time (in seconds) that the token will be valid
29
+ # after being issued.
30
+ # @param scopes [array] The scope of the resource server.
31
+ #
32
+ # @return [json] Returns the resource server.
33
+ def create_resource_server(identifier, options = {})
34
+ raise Auth0::InvalidParameter, 'Must supply a valid resource server id' if identifier.to_s.empty?
35
+ if ['<', '>'].include?(options.fetch(:name, ''))
36
+ raise Auth0::InvalidParameter, 'Name must contain at least one character. Does not allow "<" or ">"'
37
+ end
38
+ request_params = Hash[options.map { |(k, v)| [k.to_sym, v] }]
39
+ request_params[:identifier] = identifier
40
+ post(resource_servers_path, request_params)
41
+ end
42
+
43
+ # Deletes a resource server by its ID.
44
+ # @see https://auth0.com/docs/api/management/v2#!/Resource_Servers/delete_resource_servers_by_id
45
+ # @param resource_server_id [string] The id of the resource server to delete.
46
+ def delete_resource_server(resource_server_id)
47
+ raise Auth0::InvalidParameter, 'Must supply a valid resource server id' if resource_server_id.to_s.empty?
48
+ path = "#{resource_servers_path}/#{resource_server_id}"
49
+ delete(path)
50
+ end
51
+
52
+ private
53
+
54
+ # Resource Servers API path
55
+ def resource_servers_path
56
+ @resource_servers_path ||= '/api/v2/resource-servers'
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end