auth0 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-agent: *
5
+ # Disallow: /
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+ # Ping Controller Tests
3
+ class PingControllerTest < ActionController::TestCase
4
+ test 'responds with success' do
5
+ get :ping
6
+ assert_response :success
7
+ end
8
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+ # Secure Ping Controller Test
3
+ class SecuredPingControllerTest < ActionController::TestCase
4
+ def with_a_valid_token
5
+ @user = { id: 1 }
6
+ @token = Knock::AuthToken.new(payload: { sub: @user[:id] }).token
7
+ @request.env['HTTP_AUTHORIZATION'] = "Bearer #{@token}"
8
+ end
9
+
10
+ test 'responds with unauthorized' do
11
+ get :ping
12
+ assert_response :unauthorized
13
+ end
14
+
15
+ test 'responds with success when passing a valid token' do
16
+ with_a_valid_token
17
+ get :ping
18
+ assert_response :success
19
+ end
20
+
21
+ test '@current_user is set when passing a valid token' do
22
+ with_a_valid_token
23
+ get :ping
24
+ assert_equal @user[:id], @controller.current_user[:id]
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+ # Active Support
5
+ class ActiveSupport
6
+ # Test Case
7
+ class TestCase
8
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
9
+ #
10
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
11
+ # -- they do not yet inherit this setting
12
+ fixtures :all
13
+
14
+ # Add more helper methods to be used by all tests here...
15
+ end
16
+ end
@@ -4,8 +4,8 @@ module Auth0
4
4
  # {https://auth0.com/docs/auth-api}
5
5
  # Methods to use the authentication endpoints
6
6
  module AuthenticationEndpoints
7
- UP_AUTH = 'Username-Password-Authentication'
8
- JWT_BEARER = 'urn:ietf:params:oauth:grant-type:jwt-bearer'
7
+ UP_AUTH = 'Username-Password-Authentication'.freeze
8
+ JWT_BEARER = 'urn:ietf:params:oauth:grant-type:jwt-bearer'.freeze
9
9
 
10
10
  # Retrives an access token
11
11
  # @see https://auth0.com/docs/auth-api#!#post--oauth-access_token
@@ -22,6 +22,28 @@ module Auth0
22
22
  end
23
23
  end
24
24
 
25
+ # Gets the user tokens using the code obtained through passive authentication in the specified connection
26
+ # @see https://auth0.com/docs/auth-api#!#post--oauth-access_token
27
+ # @param connection [string] Currently, this endpoint only works for Facebook, Google, Twitter and Weibo
28
+ # @param scope [string] Defaults to openid. Can be 'openid name email', 'openid offline_access'
29
+ # @param redirect_uri [string] Url to redirect after authorization
30
+ # @param redirect_uri [string] The access code obtained through passive authentication
31
+ # @return [json] Returns the access_token and id_token
32
+ def obtain_user_tokens(code, redirect_uri, connection = 'facebook', scope = 'openid')
33
+ raise Auth0::InvalidParameter, 'Must supply a valid code' if code.to_s.empty?
34
+ raise Auth0::InvalidParameter, 'Must supply a valid redirect_uri' if redirect_uri.to_s.empty?
35
+ request_params = {
36
+ client_id: @client_id,
37
+ client_secret: @client_secret,
38
+ connection: connection,
39
+ grant_type: 'authorization_code',
40
+ code: code,
41
+ scope: scope,
42
+ redirect_uri: redirect_uri
43
+ }
44
+ post('/oauth/token', request_params)
45
+ end
46
+
25
47
  # Logins using username/password
26
48
  # @see https://auth0.com/docs/auth-api#!#post--oauth-ro
27
49
  # @param username [string] Username
@@ -32,8 +54,8 @@ module Auth0
32
54
  # Active Directory/LDAP, Windows Azure AD and ADF
33
55
  # @return [json] Returns the access token and id token
34
56
  def login(username, password, id_token = nil, connection_name = UP_AUTH, options = {})
35
- fail Auth0::InvalidParameter, 'Must supply a valid username' if username.to_s.empty?
36
- fail Auth0::InvalidParameter, 'Must supply a valid password' if password.to_s.empty?
57
+ raise Auth0::InvalidParameter, 'Must supply a valid username' if username.to_s.empty?
58
+ raise Auth0::InvalidParameter, 'Must supply a valid password' if password.to_s.empty?
37
59
  request_params = {
38
60
  client_id: @client_id,
39
61
  username: username,
@@ -54,8 +76,8 @@ module Auth0
54
76
  # @param connection_name [string] Connection name. Works for database connections.
55
77
  # @return [json] Returns the created user
56
78
  def signup(email, password, connection_name = UP_AUTH)
57
- fail Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty?
58
- fail Auth0::InvalidParameter, 'Must supply a valid password' if password.to_s.empty?
79
+ raise Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty?
80
+ raise Auth0::InvalidParameter, 'Must supply a valid password' if password.to_s.empty?
59
81
  request_params = {
60
82
  client_id: @client_id,
61
83
  email: email,
@@ -72,7 +94,7 @@ module Auth0
72
94
  # @param password [string] User's new password
73
95
  # @param connection_name [string] Connection name. Works for database connections.
74
96
  def change_password(email, password, connection_name = UP_AUTH)
75
- fail Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty?
97
+ raise Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty?
76
98
  request_params = {
77
99
  client_id: @client_id,
78
100
  email: email,
@@ -88,12 +110,13 @@ module Auth0
88
110
  # @param send [string] Defaults to 'link'. Can be 'code'. You can then authenticate with this user opening the link
89
111
  # @param auth_params [hash] Append/override parameters to the link (like scope, redirect_uri, protocol, etc.)
90
112
  def start_passwordless_email_flow(email, send = 'link', auth_params = {})
91
- fail Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty?
113
+ raise Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty?
92
114
  request_params = {
93
- client_id: @client_id,
94
- email: email,
95
- send: send,
96
- auth_params: auth_params
115
+ client_id: @client_id,
116
+ connection: 'email',
117
+ email: email,
118
+ send: send,
119
+ authParams: auth_params
97
120
  }
98
121
  post('/passwordless/start', request_params)
99
122
  end
@@ -102,7 +125,7 @@ module Auth0
102
125
  # @see https://auth0.com/docs/auth-api#!#post--with_sms
103
126
  # @param phone_number [string] User's phone number.
104
127
  def start_passwordless_sms_flow(phone_number)
105
- fail Auth0::InvalidParameter, 'Must supply a valid phone number' if phone_number.to_s.empty?
128
+ raise Auth0::InvalidParameter, 'Must supply a valid phone number' if phone_number.to_s.empty?
106
129
  request_params = {
107
130
  client_id: @client_id,
108
131
  connection: 'sms',
@@ -117,8 +140,8 @@ module Auth0
117
140
  # @param code [string] Verification code.
118
141
  # @return [json] Returns the access token and id token
119
142
  def phone_login(phone_number, code, scope = 'openid')
120
- fail Auth0::InvalidParameter, 'Must supply a valid phone number' if phone_number.to_s.empty?
121
- fail Auth0::InvalidParameter, 'Must supply a valid code' if code.to_s.empty?
143
+ raise Auth0::InvalidParameter, 'Must supply a valid phone number' if phone_number.to_s.empty?
144
+ raise Auth0::InvalidParameter, 'Must supply a valid code' if code.to_s.empty?
122
145
  request_params = {
123
146
  client_id: @client_id,
124
147
  username: phone_number,
@@ -132,11 +155,9 @@ module Auth0
132
155
 
133
156
  # Retrives the SAML 2.0 metadata
134
157
  # @see https://auth0.com/docs/auth-api#!#get--samlp--client_id-
135
- # @param client_id [string] Client id
136
158
  # @return [xml] SAML 2.0 metadata
137
- def saml_metadata(client_id)
138
- fail Auth0::InvalidParameter, 'Must supply a valid client_id' if client_id.to_s.empty?
139
- get("/samlp/metadata/#{client_id}")
159
+ def saml_metadata
160
+ get("/samlp/metadata/#{@client_id}")
140
161
  end
141
162
 
142
163
  # Retrives the WS-Federation metadata
@@ -151,7 +172,7 @@ module Auth0
151
172
  # @param id_token [string] Token's id.
152
173
  # @return User information associated with the user id (sub property) of the token.
153
174
  def token_info(id_token)
154
- fail Auth0::InvalidParameter, 'Must supply a valid id_token' if id_token.to_s.empty?
175
+ raise Auth0::InvalidParameter, 'Must supply a valid id_token' if id_token.to_s.empty?
155
176
  request_params = { id_token: id_token }
156
177
  post('/tokeninfo', request_params)
157
178
  end
@@ -166,7 +187,7 @@ module Auth0
166
187
  # @param extra_parameters [hash] Extra parameters.
167
188
  # @return [json] Returns the refreshed delegation token
168
189
  def refresh_delegation(refresh_token, target, scope = 'openid', api_type = 'app', extra_parameters = {})
169
- fail Auth0::InvalidParameter, 'Must supply a valid token to refresh' if refresh_token.to_s.empty?
190
+ raise Auth0::InvalidParameter, 'Must supply a valid token to refresh' if refresh_token.to_s.empty?
170
191
  request_params = {
171
192
  client_id: @client_id,
172
193
  grant_type: JWT_BEARER,
@@ -188,7 +209,7 @@ module Auth0
188
209
  # @param extra_parameters [hash] Extra parameters.
189
210
  # @return [json] Returns the refreshed delegation token
190
211
  def delegation(id_token, target, scope = 'openid', api_type = 'app', extra_parameters = {})
191
- fail Auth0::InvalidParameter, 'Must supply a valid id_token' if id_token.to_s.empty?
212
+ raise Auth0::InvalidParameter, 'Must supply a valid id_token' if id_token.to_s.empty?
192
213
  request_params = {
193
214
  client_id: @client_id,
194
215
  grant_type: JWT_BEARER,
@@ -207,8 +228,13 @@ module Auth0
207
228
  # @param impersonator_id [string] Impersonator user id id.
208
229
  # @param options [string] Additional Parameters
209
230
  # @return [string] Impersonation URL
231
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
210
232
  def impersonate(user_id, app_client_id, impersonator_id, options)
211
- fail Auth0::InvalidParameter, 'Must supply a valid user_id' if user_id.to_s.empty?
233
+ raise Auth0::InvalidParameter, 'Must supply a valid user_id' if user_id.to_s.empty?
234
+ raise Auth0::InvalidParameter, 'Must supply a valid app_client_id' if app_client_id.to_s.empty?
235
+ raise Auth0::InvalidParameter, 'Must supply a valid impersonator_id' if impersonator_id.to_s.empty?
236
+ raise Auth0::MissingParameter, 'Must supply client_secret' if @client_secret.nil?
237
+ authorization_header obtain_access_token
212
238
  request_params = {
213
239
  protocol: options.fetch(:protocol, 'oauth2'),
214
240
  impersonator_id: impersonator_id,
@@ -220,7 +246,9 @@ module Auth0
220
246
  callback_url: options.fetch(:callback_url, '')
221
247
  }
222
248
  }
223
- post("/users/#{user_id}/impersonate", request_params)
249
+ result = post("/users/#{user_id}/impersonate", request_params)
250
+ authorization_header @token
251
+ result
224
252
  end
225
253
 
226
254
  # Unlinks a User
@@ -228,8 +256,8 @@ module Auth0
228
256
  # @param access_token [string] Logged-in user access token
229
257
  # @param user_id [string] User Id
230
258
  def unlink_user(access_token, user_id)
231
- fail Auth0::InvalidParameter, 'Must supply a valid access_token' if access_token.to_s.empty?
232
- fail Auth0::InvalidParameter, 'Must supply a valid user_id' if user_id.to_s.empty?
259
+ raise Auth0::InvalidParameter, 'Must supply a valid access_token' if access_token.to_s.empty?
260
+ raise Auth0::InvalidParameter, 'Must supply a valid user_id' if user_id.to_s.empty?
233
261
  request_params = {
234
262
  access_token: access_token,
235
263
  user_id: user_id
@@ -250,13 +278,14 @@ module Auth0
250
278
  # @param options [hash] Can contain response_type, connection, state and additional_parameters.
251
279
  # @return [url] Authorization URL.
252
280
  def authorization_url(redirect_uri, options = {})
253
- fail Auth0::InvalidParameter, 'Must supply a valid redirect_uri' if redirect_uri.to_s.empty?
281
+ raise Auth0::InvalidParameter, 'Must supply a valid redirect_uri' if redirect_uri.to_s.empty?
254
282
  request_params = {
255
283
  client_id: @client_id,
256
- response_type: options.fetch(:connection, 'code'),
284
+ response_type: options.fetch(:response_type, 'code'),
257
285
  connection: options.fetch(:connection, nil),
258
- redirect_url: redirect_uri,
259
- state: options.fetch(:state, nil)
286
+ redirect_uri: redirect_uri,
287
+ state: options.fetch(:state, nil),
288
+ scope: options.fetch(:scope, nil)
260
289
  }.merge(options.fetch(:additional_parameters, {}))
261
290
 
262
291
  URI::HTTPS.build(host: @domain, path: '/authorize', query: to_query(request_params))
@@ -9,7 +9,7 @@ module Auth0
9
9
  get(path)
10
10
  end
11
11
 
12
- alias_method :get_clients, :clients
12
+ alias get_clients clients
13
13
 
14
14
  # {https://auth0.com/docs/api#!#post--api-clients}
15
15
  def create_client(name, callbacks = '')
@@ -7,14 +7,14 @@ module Auth0
7
7
  def connections
8
8
  get('/api/connections')
9
9
  end
10
- alias_method :get_connections, :connections
10
+ alias get_connections connections
11
11
 
12
12
  # {https://auth0.com/docs/api#!#get--api-connections--connection-name-}
13
13
  def connection(connection_name)
14
14
  path = "/api/connections/#{connection_name}"
15
15
  get(path)
16
16
  end
17
- alias_method :get_connection, :connection
17
+ alias get_connection connection
18
18
 
19
19
  # {https://auth0.com/docs/api#!#delete--api-connections--connection-name-}
20
20
  def delete_connection(connection_name)
@@ -30,7 +30,8 @@ module Auth0
30
30
  strategy: strategy,
31
31
  options: {
32
32
  tenant_domain: tenant_domain,
33
- domain_aliases: domain_aliases }
33
+ domain_aliases: domain_aliases
34
+ }
34
35
  }
35
36
  post(path, request_params)
36
37
  end
@@ -15,7 +15,7 @@ module Auth0
15
15
  get(path)
16
16
  end
17
17
 
18
- alias_method :search_logs, :logs
18
+ alias search_logs logs
19
19
 
20
20
  # {https://auth0.com/docs/api#!#get--api-logs--_id-}
21
21
  def log(id)
@@ -9,7 +9,7 @@ module Auth0
9
9
  get(path)
10
10
  end
11
11
 
12
- alias_method :get_rules, :rules
12
+ alias get_rules rules
13
13
 
14
14
  # https://auth0.com/docs/api#!#post--api-rules
15
15
  def create_rule(name, script, order = nil, status = true)
@@ -13,8 +13,8 @@ module Auth0
13
13
  get(path)
14
14
  end
15
15
 
16
- alias_method :users_search, :users
17
- alias_method :get_users, :users
16
+ alias users_search users
17
+ alias get_users users
18
18
 
19
19
  # {https://auth0.com/docs/api#!#get--api-users--user_id-}
20
20
  def user(user_id)
@@ -22,7 +22,7 @@ module Auth0
22
22
  get(path)
23
23
  end
24
24
 
25
- alias_method :get_user, :user
25
+ alias get_user user
26
26
 
27
27
  # {https://auth0.com/docs/api#!#get--api-users--user_id--devices}
28
28
  def user_devices(user_id)
@@ -38,7 +38,7 @@ module Auth0
38
38
  get(path)
39
39
  end
40
40
 
41
- alias_method :search_connection_users, :connection_users
41
+ alias search_connection_users connection_users
42
42
 
43
43
  # {https://auth0.com/docs/api#!#get--api-enterpriseconnections-users-search--criteria-}
44
44
  def enterpriseconnections_users(search_criteria = nil, per_page = 500)
@@ -142,7 +142,7 @@ module Auth0
142
142
 
143
143
  # {https://auth0.com/docs/api#!#delete--api-users--user_id-}
144
144
  def delete_user(user_id)
145
- fail Auth0::MissingUserId, 'if you want to remove all users use delete_users method' if user_id.to_s.empty?
145
+ raise Auth0::MissingUserId, 'if you want to remove all users use delete_users method' if user_id.to_s.empty?
146
146
  path = "/api/users/#{user_id}"
147
147
  delete(path)
148
148
  end
@@ -1,13 +1,18 @@
1
1
  require 'auth0/api/v2/blacklists'
2
2
  require 'auth0/api/v2/clients'
3
+ require 'auth0/api/v2/client_grants'
3
4
  require 'auth0/api/v2/connections'
5
+ require 'auth0/api/v2/device_credentials'
4
6
  require 'auth0/api/v2/emails'
5
7
  require 'auth0/api/v2/jobs'
6
8
  require 'auth0/api/v2/rules'
7
9
  require 'auth0/api/v2/stats'
8
10
  require 'auth0/api/v2/users'
11
+ require 'auth0/api/v2/user_blocks'
9
12
  require 'auth0/api/v2/tenants'
10
13
  require 'auth0/api/v2/tickets'
14
+ require 'auth0/api/v2/logs'
15
+ require 'auth0/api/v2/resource_servers'
11
16
 
12
17
  module Auth0
13
18
  module Api
@@ -15,14 +20,19 @@ module Auth0
15
20
  module V2
16
21
  include Auth0::Api::V2::Blacklists
17
22
  include Auth0::Api::V2::Clients
23
+ include Auth0::Api::V2::ClientGrants
18
24
  include Auth0::Api::V2::Connections
25
+ include Auth0::Api::V2::DeviceCredentials
19
26
  include Auth0::Api::V2::Emails
20
27
  include Auth0::Api::V2::Jobs
21
28
  include Auth0::Api::V2::Rules
22
29
  include Auth0::Api::V2::Stats
23
30
  include Auth0::Api::V2::Users
31
+ include Auth0::Api::V2::UserBlocks
24
32
  include Auth0::Api::V2::Tenants
25
33
  include Auth0::Api::V2::Tickets
34
+ include Auth0::Api::V2::Logs
35
+ include Auth0::Api::V2::ResourceServers
26
36
  end
27
37
  end
28
38
  end
@@ -25,7 +25,7 @@ module Auth0
25
25
  # @return [json] Returns the blacklisted token
26
26
  #
27
27
  def add_token_to_blacklist(jti, aud = nil)
28
- fail Auth0::MissingParameter, 'Must specify a valid JTI' if jti.to_s.empty?
28
+ raise Auth0::MissingParameter, 'Must specify a valid JTI' if jti.to_s.empty?
29
29
  request_params = {
30
30
  jti: jti,
31
31
  aud: aud
@@ -0,0 +1,57 @@
1
+ module Auth0
2
+ module Api
3
+ module V2
4
+ # Methods to use the client grants endpoints
5
+ module ClientGrants
6
+ attr_reader :client_grants_path
7
+
8
+ # Retrieves a list of all client grants.
9
+ # @see https://auth0.com/docs/api/management/v2#!/client_grants/get_client_grants
10
+ #
11
+ # @return [json] Returns the client grants.
12
+ def client_grants
13
+ get(client_grants_path)
14
+ end
15
+ alias get_all_client_grants client_grants
16
+
17
+ # Creates a new client grant.
18
+ # @see https://auth0.com/docs/api/management/v2#!/client_grants/post_client_grants
19
+ # @param options [hash] The Hash options used to define the client grant's properties.
20
+ #
21
+ # @return [json] Returns the created client grant.
22
+ def create_client_grant(options = {})
23
+ request_params = Hash[options.map { |(k, v)| [k.to_sym, v] }]
24
+ post(client_grants_path, request_params)
25
+ end
26
+
27
+ # Deletes a client grant given its id.
28
+ # @see https://auth0.com/docs/api/management/v2#!/client_grants/delete_client_grants_by_id
29
+ # @param client_id [string] The id of the client grant to delete.
30
+ def delete_client_grant(client_grant_id)
31
+ raise Auth0::InvalidParameter, 'Must specify a client grant id' if client_grant_id.to_s.empty?
32
+ path = "#{client_grants_path}/#{client_grant_id}"
33
+ delete(path)
34
+ end
35
+
36
+ # Updates a client grant.
37
+ # @see https://auth0.com/docs/api/management/v2#!/client_grants/patch_client_grants_by_id
38
+ # @param client_id [string] The id of the client grant to update.
39
+ # @param options [hash] The Hash options used to define the client grant's properties.
40
+ def patch_client_grant(client_grant_id, options)
41
+ raise Auth0::InvalidParameter, 'Must specify a client grant id' if client_grant_id.to_s.empty?
42
+ raise Auth0::InvalidParameter, 'Must specify a valid body' if options.to_s.empty?
43
+ path = "#{client_grants_path}/#{client_grant_id}"
44
+ patch(path, options)
45
+ end
46
+ alias update_client_grant patch_client_grant
47
+
48
+ private
49
+
50
+ # Client Grants API path
51
+ def client_grants_path
52
+ @client_grants_path ||= '/api/v2/client-grants'
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end