doorkeeper-mongodb 5.2.1 → 5.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -27
- data/lib/doorkeeper/orm/concerns/mongoid/ownership.rb +1 -1
- data/lib/doorkeeper/orm/concerns/mongoid/resource_ownerable.rb +1 -1
- data/lib/doorkeeper/orm/mongoid4.rb +18 -0
- data/lib/doorkeeper/orm/mongoid5.rb +18 -0
- data/lib/doorkeeper/orm/mongoid6.rb +18 -0
- data/lib/doorkeeper/orm/mongoid7.rb +18 -0
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_grant_mixin.rb +7 -6
- data/lib/doorkeeper-mongodb/mixins/mongoid/access_token_mixin.rb +8 -5
- data/lib/doorkeeper-mongodb/mixins/mongoid/application_mixin.rb +82 -5
- data/lib/doorkeeper-mongodb/mixins/mongoid/base_mixin.rb +0 -8
- data/lib/doorkeeper-mongodb/mixins/mongoid/json_serializable.rb +17 -0
- data/lib/doorkeeper-mongodb/version.rb +1 -1
- data/lib/doorkeeper-mongodb.rb +1 -0
- data/spec/controllers/application_metal_controller_spec.rb +4 -4
- data/spec/controllers/applications_controller_spec.rb +198 -202
- data/spec/controllers/authorizations_controller_spec.rb +32 -31
- data/spec/controllers/protected_resources_controller_spec.rb +10 -10
- data/spec/controllers/token_info_controller_spec.rb +1 -1
- data/spec/controllers/tokens_controller_spec.rb +105 -62
- data/spec/doorkeeper/redirect_uri_validator_spec.rb +183 -0
- data/spec/{lib → doorkeeper}/server_spec.rb +5 -4
- data/spec/{lib → doorkeeper}/stale_records_cleaner_spec.rb +8 -7
- data/spec/{version → doorkeeper}/version_spec.rb +3 -3
- data/spec/dummy/app/assets/config/manifest.js +0 -0
- data/spec/dummy/app/controllers/application_controller.rb +0 -0
- data/spec/dummy/app/controllers/custom_authorizations_controller.rb +0 -0
- data/spec/dummy/app/controllers/full_protected_resources_controller.rb +0 -0
- data/spec/dummy/app/controllers/home_controller.rb +0 -0
- data/spec/dummy/app/controllers/metal_controller.rb +0 -0
- data/spec/dummy/app/controllers/semi_protected_resources_controller.rb +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +0 -0
- data/spec/dummy/app/models/user.rb +0 -1
- data/spec/dummy/app/views/home/index.html.erb +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +0 -0
- data/spec/dummy/config/application.rb +0 -0
- data/spec/dummy/config/boot.rb +0 -0
- data/spec/dummy/config/database.yml +0 -0
- data/spec/dummy/config/environment.rb +0 -0
- data/spec/dummy/config/environments/development.rb +0 -0
- data/spec/dummy/config/environments/production.rb +0 -0
- data/spec/dummy/config/environments/test.rb +0 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/dummy/config/initializers/doorkeeper.rb +0 -0
- data/spec/dummy/config/initializers/secret_token.rb +0 -0
- data/spec/dummy/config/initializers/session_store.rb +0 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -0
- data/spec/dummy/config/locales/doorkeeper.en.yml +0 -0
- data/spec/dummy/config/mongo.yml +2 -2
- data/spec/dummy/config/routes.rb +0 -0
- data/spec/dummy/config.ru +0 -0
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +0 -0
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +0 -0
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +0 -0
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +0 -0
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +0 -0
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +0 -0
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +0 -0
- data/spec/dummy/db/schema.rb +0 -0
- data/spec/dummy/public/404.html +0 -0
- data/spec/dummy/public/422.html +0 -0
- data/spec/dummy/public/500.html +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/-o/-ofn45zIfO5vx4VD6m6NXesLf6da5usA-Sbw2SVju3o.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/0_/0_ouGcG_o_1zmVmBe-tdQYk594LBwVa1bumjrKtdfEw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/2X/2XMMcHbyTSRqh1GkV0xzyIETNtt-zgN6iniziShaKmQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/4Q/4QQw-pMQ98JIj3xdcFhGBQdysdGPY9rWffRqWMmyjew.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/7H/7HjRsym0tTpXFCVhWt6kteMs_-CozKVbr9s5syHm8es.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8B/8BxJyv22HPFHu1se_l2J8qW1N9NzZ16UOWOy1YMSgs4.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/8D/8DJG7JfPvShfLLyeSom6NZ_TcQc6QH27tJ7prEWZPfI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/9x/9xjtGv-yKjj62x9uFwBZg8pTSh9ERPAgANwNo9uwIaA.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Bt/BtXO7f0PZ8DNt3TMLYM-zY7LkbWa_KgyB0v1V98M1CQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/E0/E02f1Q2tutWumMulGCFNfqQNjvEP_hMAK_5E83eWepI.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/EZ/EZGpd6pUEJZxO6uT2yIS4Fpn5KX7VDgC9VB3AaemF5Q.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/FJ/FJlQpfMtpRbrM5P8A7d2FAelFKwo6GrVs2xks8z5GKU.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/L8/L8mOWakJlWKr6MU85rj0V7yGFfNyIR6vE6YXtqArPGw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Lk/LklIq5hrBAPESXVUpFMwQ9L-1qTj90sPVi6U19_Xi-Q.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/MB/MBWRxa9S470ee8suxVKp0jYgv6K6FQOqKGV0kPGQNMs.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ma/MaK3K1AoZZ4xM5fOOifhROd73hfZJpP4yGbkGdoYtEk.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/PA/PAH_jI20wRw12tngeJ-V619c30avNLDu5U9Z-9Pc5SQ.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Ph/Ph7RtH_NvG2I8XpTa8mA8SBQXZDzBPVIh4CH6g7OXJ0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/{eS/eSL1QMz46gKLM0GR6S9fL6uyARPxOImcappZ9_ZtSyg.cache → Pm/PmheG0PGFqDws1qgFOxOyIL-gpMof3Ar9eSRKVLYuik.cache} +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Pn/PnXU_mkG2fLZFm9BwiZ03BZdBTjKuInP-cRXjHS7yJo.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Qs/QsVgO6vM5Yn9oeYTYlrqtyVnK6sdVDWDa083N7zpfHw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/So/So59ksdx2dw-_A3-zFZ6Palr7fROjm7_0JDZb04temw.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/Wt/WtXL_iDofLeTH_v0Yf3PM421r9b1V0g-VBvMPeu9KA0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/b6/b6QRH6ZdCc0e6bUWu4qni_kZmptaMgWciO8Jl9q6_p8.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/dX/dX6FDdUIy8yBCOoaoXcjf71rX9N_bpiXGJ4Urt32NTk.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/jC/jCTZ1jAldKBn4OTANBBmCKzxLrDgok1ur4meoTqlDNg.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/qT/qTQIQsmS0Wbbg2JxNn9rxdI5qVOTg5SfyQdaTvr9vLo.cache +0 -0
- data/spec/dummy/tmp/cache/assets/sprockets/v4.0.0/yN/yNOFGOsnHmxXNMkuEAWuL1u3jlmdvrdeoTx6DDJ1in8.cache +0 -0
- data/spec/factories.rb +0 -0
- data/spec/grape/grape_integration_spec.rb +1 -1
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
- data/spec/lib/config_spec.rb +23 -12
- data/spec/lib/doorkeeper_spec.rb +4 -4
- data/spec/lib/models/expirable_spec.rb +9 -9
- data/spec/lib/models/reusable_spec.rb +2 -2
- data/spec/lib/models/revocable_spec.rb +4 -7
- data/spec/lib/models/scopes_spec.rb +7 -7
- data/spec/lib/models/secret_storable_spec.rb +9 -8
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +23 -27
- data/spec/lib/oauth/authorization_code_request_spec.rb +6 -6
- data/spec/lib/oauth/base_request_spec.rb +11 -27
- data/spec/lib/oauth/base_response_spec.rb +2 -2
- data/spec/lib/oauth/client/credentials_spec.rb +25 -25
- data/spec/lib/oauth/client_credentials/creator_spec.rb +89 -91
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +84 -86
- data/spec/lib/oauth/client_credentials/validation_spec.rb +72 -39
- data/spec/lib/oauth/client_credentials_integration_spec.rb +5 -5
- data/spec/lib/oauth/client_credentials_request_spec.rb +7 -10
- data/spec/lib/oauth/client_spec.rb +8 -8
- data/spec/lib/oauth/code_request_spec.rb +5 -5
- data/spec/lib/oauth/code_response_spec.rb +4 -4
- data/spec/lib/oauth/error_response_spec.rb +6 -5
- data/spec/lib/oauth/error_spec.rb +1 -1
- data/spec/lib/oauth/forbidden_token_response_spec.rb +2 -2
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +37 -37
- data/spec/lib/oauth/helpers/unique_token_spec.rb +2 -2
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +54 -54
- data/spec/lib/oauth/invalid_request_response_spec.rb +6 -6
- data/spec/lib/oauth/invalid_token_response_spec.rb +4 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +10 -9
- data/spec/lib/oauth/pre_authorization_spec.rb +20 -8
- data/spec/lib/oauth/refresh_token_request_spec.rb +10 -10
- data/spec/lib/oauth/scopes_spec.rb +14 -14
- data/spec/lib/oauth/token_request_spec.rb +9 -9
- data/spec/lib/oauth/token_response_spec.rb +5 -5
- data/spec/lib/oauth/token_spec.rb +5 -5
- data/spec/lib/option_spec.rb +1 -1
- data/spec/lib/request/strategy_spec.rb +34 -37
- data/spec/lib/secret_storing/base_spec.rb +3 -2
- data/spec/lib/secret_storing/bcrypt_spec.rb +2 -1
- data/spec/lib/secret_storing/plain_spec.rb +2 -1
- data/spec/lib/secret_storing/sha256_hash_spec.rb +2 -1
- data/spec/models/doorkeeper/access_grant_spec.rb +7 -9
- data/spec/models/doorkeeper/access_token_spec.rb +20 -26
- data/spec/models/doorkeeper/application_spec.rb +83 -26
- data/spec/requests/applications/applications_request_spec.rb +91 -93
- data/spec/requests/applications/authorized_applications_spec.rb +0 -0
- data/spec/requests/endpoints/authorization_spec.rb +1 -1
- data/spec/requests/endpoints/token_spec.rb +22 -16
- data/spec/requests/flows/authorization_code_errors_spec.rb +12 -8
- data/spec/requests/flows/authorization_code_spec.rb +108 -79
- data/spec/requests/flows/client_credentials_spec.rb +57 -45
- data/spec/requests/flows/implicit_grant_errors_spec.rb +0 -0
- data/spec/requests/flows/implicit_grant_spec.rb +4 -4
- data/spec/requests/flows/password_spec.rb +253 -213
- data/spec/requests/flows/refresh_token_spec.rb +53 -39
- data/spec/requests/flows/revoke_token_spec.rb +24 -24
- data/spec/requests/flows/skip_authorization_spec.rb +1 -1
- data/spec/requests/protected_resources/metal_spec.rb +2 -2
- data/spec/requests/protected_resources/private_api_spec.rb +0 -0
- data/spec/routing/custom_controller_routes_spec.rb +1 -1
- data/spec/routing/default_routes_spec.rb +1 -1
- data/spec/routing/scoped_routes_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -0
- data/spec/spec_helper_integration.rb +0 -0
- data/spec/support/dependencies/factory_bot.rb +0 -0
- data/spec/support/doorkeeper_rspec.rb +0 -0
- data/spec/support/helpers/access_token_request_helper.rb +0 -0
- data/spec/support/helpers/authorization_request_helper.rb +0 -0
- data/spec/support/helpers/config_helper.rb +0 -0
- data/spec/support/helpers/model_helper.rb +0 -0
- data/spec/support/helpers/request_spec_helper.rb +1 -13
- data/spec/support/helpers/url_helper.rb +2 -2
- data/spec/support/orm/active_record.rb +0 -0
- data/spec/support/orm/mongoid4.rb +1 -1
- data/spec/support/orm/mongoid5.rb +1 -1
- data/spec/support/orm/mongoid6.rb +1 -1
- data/spec/support/orm/mongoid7.rb +1 -1
- data/spec/support/shared/controllers_shared_context.rb +5 -38
- data/spec/support/shared/hashing_shared_context.rb +4 -0
- data/spec/support/shared/models_shared_examples.rb +6 -6
- metadata +154 -167
- data/spec/dummy/log/test.log +0 -6108
@@ -49,11 +49,13 @@ feature "Authorization Code Flow" do
|
|
49
49
|
|
50
50
|
access_token_should_exist_for(@client, @resource_owner)
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
expect(json_response).to match(
|
53
|
+
"access_token" => Doorkeeper::AccessToken.first.token,
|
54
|
+
"token_type" => "Bearer",
|
55
|
+
"expires_in" => 7200,
|
56
|
+
"scope" => "default",
|
57
|
+
"created_at" => an_instance_of(Integer),
|
58
|
+
)
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
@@ -124,8 +126,10 @@ feature "Authorization Code Flow" do
|
|
124
126
|
|
125
127
|
expect(Doorkeeper::AccessToken.count).to be_zero
|
126
128
|
|
127
|
-
|
128
|
-
|
129
|
+
expect(json_response).to match(
|
130
|
+
"error" => "invalid_request",
|
131
|
+
"error_description" => translated_invalid_request_error_message(:missing_param, :code),
|
132
|
+
)
|
129
133
|
end
|
130
134
|
|
131
135
|
scenario "resource owner requests an access token with authorization code" do
|
@@ -137,11 +141,13 @@ feature "Authorization Code Flow" do
|
|
137
141
|
|
138
142
|
access_token_should_exist_for(@client, @resource_owner)
|
139
143
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
144
|
+
expect(json_response).to match(
|
145
|
+
"access_token" => Doorkeeper::AccessToken.first.token,
|
146
|
+
"token_type" => "Bearer",
|
147
|
+
"expires_in" => 7200,
|
148
|
+
"scope" => "default",
|
149
|
+
"created_at" => an_instance_of(Integer),
|
150
|
+
)
|
145
151
|
end
|
146
152
|
|
147
153
|
scenario "resource owner requests an access token with authorization code but without secret" do
|
@@ -156,8 +162,10 @@ feature "Authorization Code Flow" do
|
|
156
162
|
|
157
163
|
expect(Doorkeeper::AccessToken.count).to be_zero
|
158
164
|
|
159
|
-
|
160
|
-
|
165
|
+
expect(json_response).to match(
|
166
|
+
"error" => "invalid_client",
|
167
|
+
"error_description" => translated_error_message(:invalid_client),
|
168
|
+
)
|
161
169
|
end
|
162
170
|
|
163
171
|
scenario "resource owner requests an access token with authorization code but without client id" do
|
@@ -172,8 +180,10 @@ feature "Authorization Code Flow" do
|
|
172
180
|
|
173
181
|
expect(Doorkeeper::AccessToken.count).to be_zero
|
174
182
|
|
175
|
-
|
176
|
-
|
183
|
+
expect(json_response).to match(
|
184
|
+
"error" => "invalid_client",
|
185
|
+
"error_description" => translated_error_message(:invalid_client),
|
186
|
+
)
|
177
187
|
end
|
178
188
|
|
179
189
|
scenario "silently authorizes if matching token exists" do
|
@@ -192,7 +202,7 @@ feature "Authorization Code Flow" do
|
|
192
202
|
end
|
193
203
|
|
194
204
|
context "with PKCE" do
|
195
|
-
context "plain" do
|
205
|
+
context "when plain" do
|
196
206
|
let(:code_challenge) { "a45a9fea-0676-477e-95b1-a40f72ac3cfb" }
|
197
207
|
let(:code_verifier) { "a45a9fea-0676-477e-95b1-a40f72ac3cfb" }
|
198
208
|
|
@@ -216,8 +226,10 @@ feature "Authorization Code Flow" do
|
|
216
226
|
authorization_code = current_params["code"]
|
217
227
|
create_access_token authorization_code, @client, code_verifier
|
218
228
|
|
219
|
-
|
220
|
-
|
229
|
+
expect(json_response).to match(
|
230
|
+
"error" => "invalid_grant",
|
231
|
+
"error_description" => translated_error_message(:invalid_grant),
|
232
|
+
)
|
221
233
|
end
|
222
234
|
|
223
235
|
scenario "mobile app requests an access token with authorization code and plain code challenge method" do
|
@@ -233,11 +245,13 @@ feature "Authorization Code Flow" do
|
|
233
245
|
|
234
246
|
access_token_should_exist_for(@client, @resource_owner)
|
235
247
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
248
|
+
expect(json_response).to match(
|
249
|
+
"access_token" => Doorkeeper::AccessToken.first.token,
|
250
|
+
"token_type" => "Bearer",
|
251
|
+
"expires_in" => 7200,
|
252
|
+
"scope" => "default",
|
253
|
+
"created_at" => an_instance_of(Integer),
|
254
|
+
)
|
241
255
|
end
|
242
256
|
|
243
257
|
scenario "mobile app requests an access token with authorization code but without code_verifier" do
|
@@ -251,9 +265,10 @@ feature "Authorization Code Flow" do
|
|
251
265
|
authorization_code = current_params["code"]
|
252
266
|
create_access_token authorization_code, @client, nil
|
253
267
|
|
254
|
-
|
255
|
-
|
256
|
-
|
268
|
+
expect(json_response).to match(
|
269
|
+
"error" => "invalid_request",
|
270
|
+
"error_description" => translated_invalid_request_error_message(:missing_param, :code_verifier),
|
271
|
+
)
|
257
272
|
end
|
258
273
|
|
259
274
|
scenario "mobile app requests an access token with authorization code with wrong code_verifier" do
|
@@ -267,13 +282,15 @@ feature "Authorization Code Flow" do
|
|
267
282
|
authorization_code = current_params["code"]
|
268
283
|
create_access_token authorization_code, @client, "wrong_code_verifier"
|
269
284
|
|
270
|
-
|
271
|
-
|
272
|
-
|
285
|
+
expect(json_response).not_to include("access_token")
|
286
|
+
expect(json_response).to match(
|
287
|
+
"error" => "invalid_grant",
|
288
|
+
"error_description" => translated_error_message(:invalid_grant),
|
289
|
+
)
|
273
290
|
end
|
274
291
|
end
|
275
292
|
|
276
|
-
context "
|
293
|
+
context "when S256" do
|
277
294
|
let(:code_challenge) { "Oz733NtQ0rJP8b04fgZMJMwprn6Iw8sMCT_9bR1q4tA" }
|
278
295
|
let(:code_verifier) { "a45a9fea-0676-477e-95b1-a40f72ac3cfb" }
|
279
296
|
|
@@ -303,11 +320,13 @@ feature "Authorization Code Flow" do
|
|
303
320
|
|
304
321
|
access_token_should_exist_for(@client, @resource_owner)
|
305
322
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
323
|
+
expect(json_response).to match(
|
324
|
+
"access_token" => Doorkeeper::AccessToken.first.token,
|
325
|
+
"token_type" => "Bearer",
|
326
|
+
"expires_in" => 7200,
|
327
|
+
"scope" => "default",
|
328
|
+
"created_at" => an_instance_of(Integer),
|
329
|
+
)
|
311
330
|
end
|
312
331
|
|
313
332
|
scenario "mobile app requests an access token with authorization code and without secret" do
|
@@ -325,9 +344,11 @@ feature "Authorization Code Flow" do
|
|
325
344
|
redirect_uri: @client.redirect_uri,
|
326
345
|
code_verifier: code_verifier,
|
327
346
|
)
|
328
|
-
|
329
|
-
|
330
|
-
|
347
|
+
|
348
|
+
expect(json_response).to match(
|
349
|
+
"error" => "invalid_client",
|
350
|
+
"error_description" => translated_error_message(:invalid_client),
|
351
|
+
)
|
331
352
|
end
|
332
353
|
|
333
354
|
scenario "mobile app requests an access token with authorization code and without secret but is marked as not confidential" do
|
@@ -342,11 +363,14 @@ feature "Authorization Code Flow" do
|
|
342
363
|
redirect_uri: @client.redirect_uri,
|
343
364
|
code_verifier: code_verifier,
|
344
365
|
)
|
345
|
-
should_not_have_json "error"
|
346
366
|
|
347
|
-
|
348
|
-
|
349
|
-
|
367
|
+
expect(json_response).to match(
|
368
|
+
"access_token" => Doorkeeper::AccessToken.first.token,
|
369
|
+
"token_type" => "Bearer",
|
370
|
+
"expires_in" => 7200,
|
371
|
+
"scope" => "default",
|
372
|
+
"created_at" => an_instance_of(Integer),
|
373
|
+
)
|
350
374
|
end
|
351
375
|
|
352
376
|
scenario "mobile app requests an access token with authorization code but no code verifier" do
|
@@ -360,9 +384,11 @@ feature "Authorization Code Flow" do
|
|
360
384
|
authorization_code = current_params["code"]
|
361
385
|
create_access_token authorization_code, @client
|
362
386
|
|
363
|
-
|
364
|
-
|
365
|
-
|
387
|
+
expect(json_response).not_to include("access_token")
|
388
|
+
expect(json_response).to match(
|
389
|
+
"error" => "invalid_request",
|
390
|
+
"error_description" => translated_invalid_request_error_message(:missing_param, :code_verifier),
|
391
|
+
)
|
366
392
|
end
|
367
393
|
|
368
394
|
scenario "mobile app requests an access token with authorization code with wrong verifier" do
|
@@ -376,12 +402,13 @@ feature "Authorization Code Flow" do
|
|
376
402
|
authorization_code = current_params["code"]
|
377
403
|
create_access_token authorization_code, @client, "incorrect-code-verifier"
|
378
404
|
|
379
|
-
|
380
|
-
|
381
|
-
|
405
|
+
expect(json_response).to match(
|
406
|
+
"error" => "invalid_grant",
|
407
|
+
"error_description" => translated_error_message(:invalid_grant),
|
408
|
+
)
|
382
409
|
end
|
383
410
|
|
384
|
-
scenario "
|
411
|
+
scenario "code_challenge_methhod in token request is totally ignored" do
|
385
412
|
visit authorization_endpoint_url(
|
386
413
|
client: @client,
|
387
414
|
code_challenge: code_challenge,
|
@@ -397,9 +424,10 @@ feature "Authorization Code Flow" do
|
|
397
424
|
code_challenge_method: "plain",
|
398
425
|
)
|
399
426
|
|
400
|
-
|
401
|
-
|
402
|
-
|
427
|
+
expect(json_response).to match(
|
428
|
+
"error" => "invalid_grant",
|
429
|
+
"error_description" => translated_error_message(:invalid_grant),
|
430
|
+
)
|
403
431
|
end
|
404
432
|
|
405
433
|
scenario "expects to set code_challenge_method explicitely without fallback" do
|
@@ -477,7 +505,7 @@ feature "Authorization Code Flow" do
|
|
477
505
|
|
478
506
|
expect(Doorkeeper::AccessToken.count).to be(2)
|
479
507
|
|
480
|
-
|
508
|
+
expect(json_response).to include("access_token" => Doorkeeper::AccessToken.last.token)
|
481
509
|
end
|
482
510
|
|
483
511
|
scenario "resource owner authorizes the client with extra scopes" do
|
@@ -490,41 +518,42 @@ feature "Authorization Code Flow" do
|
|
490
518
|
|
491
519
|
expect(Doorkeeper::AccessToken.count).to be(2)
|
492
520
|
|
493
|
-
|
521
|
+
expect(json_response).to include("access_token" => Doorkeeper::AccessToken.last.token)
|
494
522
|
access_token_should_have_scopes :public, :write
|
495
523
|
end
|
496
524
|
end
|
497
|
-
end
|
498
525
|
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
526
|
+
context "when two requests sent" do
|
527
|
+
before do
|
528
|
+
Doorkeeper.configure do
|
529
|
+
orm DOORKEEPER_ORM
|
530
|
+
use_refresh_token
|
531
|
+
end
|
505
532
|
|
506
|
-
|
507
|
-
|
533
|
+
client_exists
|
534
|
+
end
|
508
535
|
|
509
|
-
|
510
|
-
|
536
|
+
describe "issuing a refresh token" do
|
537
|
+
let(:resource_owner) { FactoryBot.create(:resource_owner) }
|
511
538
|
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
539
|
+
before do
|
540
|
+
authorization_code_exists application: @client,
|
541
|
+
resource_owner_id: resource_owner.id,
|
542
|
+
resource_owner_type: resource_owner.class.name
|
543
|
+
end
|
517
544
|
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
545
|
+
it "second of simultaneous client requests get an error for revoked access token" do
|
546
|
+
authorization_code = Doorkeeper::AccessGrant.first.token
|
547
|
+
allow_any_instance_of(Doorkeeper::AccessGrant)
|
548
|
+
.to receive(:revoked?).and_return(false, true)
|
522
549
|
|
523
|
-
|
550
|
+
page.driver.post token_endpoint_url(code: authorization_code, client: @client)
|
524
551
|
|
525
|
-
|
526
|
-
|
527
|
-
|
552
|
+
expect(json_response).to match(
|
553
|
+
"error" => "invalid_grant",
|
554
|
+
"error_description" => translated_error_message(:invalid_grant),
|
555
|
+
)
|
556
|
+
end
|
528
557
|
end
|
529
558
|
end
|
530
559
|
end
|
@@ -2,23 +2,22 @@
|
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
|
-
describe "Client Credentials Request" do
|
5
|
+
RSpec.describe "Client Credentials Request" do
|
6
6
|
let(:client) { FactoryBot.create :application }
|
7
7
|
|
8
|
-
context "a valid request" do
|
8
|
+
context "with a valid request" do
|
9
9
|
it "authorizes the client and returns the token response" do
|
10
10
|
headers = authorization client.uid, client.secret
|
11
11
|
params = { grant_type: "client_credentials" }
|
12
12
|
|
13
13
|
post "/oauth/token", params: params, headers: headers
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
should_not_have_json "error_description"
|
15
|
+
expect(json_response).to match(
|
16
|
+
"access_token" => Doorkeeper::AccessToken.first.token,
|
17
|
+
"token_type" => "Bearer",
|
18
|
+
"expires_in" => Doorkeeper.configuration.access_token_expires_in,
|
19
|
+
"created_at" => an_instance_of(Integer),
|
20
|
+
)
|
22
21
|
end
|
23
22
|
|
24
23
|
context "with scopes" do
|
@@ -33,34 +32,38 @@ describe "Client Credentials Request" do
|
|
33
32
|
|
34
33
|
post "/oauth/token", params: params, headers: headers
|
35
34
|
|
36
|
-
|
37
|
-
|
35
|
+
expect(json_response).to include(
|
36
|
+
"access_token" => Doorkeeper::AccessToken.first.token,
|
37
|
+
"scope" => "write",
|
38
|
+
)
|
38
39
|
end
|
39
40
|
|
40
|
-
context "
|
41
|
+
context "when scopes are default" do
|
41
42
|
it "adds the scope to the token an returns in the response" do
|
42
43
|
headers = authorization client.uid, client.secret
|
43
44
|
params = { grant_type: "client_credentials", scope: "public" }
|
44
45
|
|
45
46
|
post "/oauth/token", params: params, headers: headers
|
46
47
|
|
47
|
-
|
48
|
-
|
48
|
+
expect(json_response).to include(
|
49
|
+
"access_token" => Doorkeeper::AccessToken.first.token,
|
50
|
+
"scope" => "public",
|
51
|
+
)
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
52
|
-
context "
|
55
|
+
context "when scopes are invalid" do
|
53
56
|
it "does not authorize the client and returns the error" do
|
54
57
|
headers = authorization client.uid, client.secret
|
55
58
|
params = { grant_type: "client_credentials", scope: "random" }
|
56
59
|
|
57
60
|
post "/oauth/token", params: params, headers: headers
|
58
61
|
|
59
|
-
should_have_json "error", "invalid_scope"
|
60
|
-
should_have_json "error_description", translated_error_message(:invalid_scope)
|
61
|
-
should_not_have_json "access_token"
|
62
|
-
|
63
62
|
expect(response.status).to eq(400)
|
63
|
+
expect(json_response).to match(
|
64
|
+
"error" => "invalid_scope",
|
65
|
+
"error_description" => translated_error_message(:invalid_scope),
|
66
|
+
)
|
64
67
|
end
|
65
68
|
end
|
66
69
|
end
|
@@ -82,8 +85,10 @@ describe "Client Credentials Request" do
|
|
82
85
|
|
83
86
|
post "/oauth/token", params: params, headers: headers
|
84
87
|
|
85
|
-
|
86
|
-
|
88
|
+
expect(json_response).to match(
|
89
|
+
"error" => "unauthorized_client",
|
90
|
+
"error_description" => translated_error_message(:unauthorized_client),
|
91
|
+
)
|
87
92
|
end
|
88
93
|
|
89
94
|
scenario "allows the request when satisfies condition" do
|
@@ -94,13 +99,12 @@ describe "Client Credentials Request" do
|
|
94
99
|
|
95
100
|
post "/oauth/token", params: params, headers: headers
|
96
101
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
should_not_have_json "error_description"
|
102
|
+
expect(json_response).to match(
|
103
|
+
"access_token" => Doorkeeper::AccessToken.first.token,
|
104
|
+
"token_type" => "Bearer",
|
105
|
+
"expires_in" => 7200,
|
106
|
+
"created_at" => an_instance_of(Integer),
|
107
|
+
)
|
104
108
|
end
|
105
109
|
end
|
106
110
|
|
@@ -122,8 +126,10 @@ describe "Client Credentials Request" do
|
|
122
126
|
token = Doorkeeper::AccessToken.first
|
123
127
|
|
124
128
|
expect(token.application_id).to eq client.id
|
125
|
-
|
126
|
-
|
129
|
+
expect(json_response).to include(
|
130
|
+
"access_token" => token.token,
|
131
|
+
"scope" => "public",
|
132
|
+
)
|
127
133
|
end
|
128
134
|
|
129
135
|
it "issues new token with multiple default scopes that are present in application scopes" do
|
@@ -139,30 +145,33 @@ describe "Client Credentials Request" do
|
|
139
145
|
token = Doorkeeper::AccessToken.first
|
140
146
|
|
141
147
|
expect(token.application_id).to eq client.id
|
142
|
-
|
143
|
-
|
148
|
+
expect(json_response).to include(
|
149
|
+
"access_token" => token.token,
|
150
|
+
"scope" => "public read",
|
151
|
+
)
|
144
152
|
end
|
145
153
|
end
|
146
154
|
|
147
|
-
context "
|
155
|
+
context "when request is invalid" do
|
148
156
|
it "does not authorize the client and returns the error" do
|
149
157
|
headers = {}
|
150
158
|
params = { grant_type: "client_credentials" }
|
151
159
|
|
152
160
|
post "/oauth/token", params: params, headers: headers
|
153
161
|
|
154
|
-
should_have_json "error", "invalid_client"
|
155
|
-
should_have_json "error_description", translated_error_message(:invalid_client)
|
156
|
-
should_not_have_json "access_token"
|
157
|
-
|
158
162
|
expect(response.status).to eq(401)
|
163
|
+
|
164
|
+
expect(json_response).to match(
|
165
|
+
"error" => "invalid_client",
|
166
|
+
"error_description" => translated_error_message(:invalid_client),
|
167
|
+
)
|
159
168
|
end
|
160
169
|
end
|
161
170
|
|
162
171
|
context "when revoke_previous_client_credentials_token is true" do
|
163
172
|
before do
|
164
|
-
allow(Doorkeeper.config).to receive(:reuse_access_token)
|
165
|
-
allow(Doorkeeper.config).to receive(:revoke_previous_client_credentials_token)
|
173
|
+
allow(Doorkeeper.config).to receive(:reuse_access_token).and_return(false)
|
174
|
+
allow(Doorkeeper.config).to receive(:revoke_previous_client_credentials_token?).and_return(true)
|
166
175
|
end
|
167
176
|
|
168
177
|
it "revokes the previous token" do
|
@@ -170,15 +179,15 @@ describe "Client Credentials Request" do
|
|
170
179
|
params = { grant_type: "client_credentials" }
|
171
180
|
|
172
181
|
post "/oauth/token", params: params, headers: headers
|
173
|
-
|
182
|
+
expect(json_response).to include("access_token" => Doorkeeper::AccessToken.first.token)
|
174
183
|
|
175
184
|
token = Doorkeeper::AccessToken.first
|
176
185
|
|
177
186
|
post "/oauth/token", params: params, headers: headers
|
178
|
-
|
187
|
+
expect(json_response).to include("access_token" => Doorkeeper::AccessToken.last.token)
|
179
188
|
|
180
|
-
expect(token.reload
|
181
|
-
expect(Doorkeeper::AccessToken.last
|
189
|
+
expect(token.reload).to be_revoked
|
190
|
+
expect(Doorkeeper::AccessToken.last).not_to be_revoked
|
182
191
|
end
|
183
192
|
|
184
193
|
context "with a simultaneous request" do
|
@@ -194,8 +203,11 @@ describe "Client Credentials Request" do
|
|
194
203
|
params = { grant_type: "client_credentials" }
|
195
204
|
|
196
205
|
post "/oauth/token", params: params, headers: headers
|
197
|
-
|
198
|
-
|
206
|
+
|
207
|
+
expect(json_response).to match(
|
208
|
+
"error" => "invalid_token_reuse",
|
209
|
+
"error_description" => translated_error_message(:server_error),
|
210
|
+
)
|
199
211
|
end
|
200
212
|
end
|
201
213
|
end
|
File without changes
|
@@ -44,7 +44,7 @@ feature "Implicit Grant Flow (feature spec)" do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
describe "Implicit Grant Flow (request spec)" do
|
47
|
+
RSpec.describe "Implicit Grant Flow (request spec)" do
|
48
48
|
before do
|
49
49
|
default_scopes_exist :default
|
50
50
|
config_is_set(:authenticate_resource_owner) { User.first || redirect_to("/sign_in") }
|
@@ -53,8 +53,8 @@ describe "Implicit Grant Flow (request spec)" do
|
|
53
53
|
create_resource_owner
|
54
54
|
end
|
55
55
|
|
56
|
-
context "
|
57
|
-
it "
|
56
|
+
context "when reuse_access_token enabled" do
|
57
|
+
it "returns a new token each request" do
|
58
58
|
allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(false)
|
59
59
|
|
60
60
|
token = client_is_authorized(@client, @resource_owner, scopes: "default")
|
@@ -71,7 +71,7 @@ describe "Implicit Grant Flow (request spec)" do
|
|
71
71
|
expect(response.location).not_to include(token.token)
|
72
72
|
end
|
73
73
|
|
74
|
-
it "
|
74
|
+
it "returns the same token if it is still accessible" do
|
75
75
|
allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
|
76
76
|
|
77
77
|
token = client_is_authorized(@client, @resource_owner, scopes: "default")
|