doorkeeper 5.1.0 → 5.3.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.
- checksums.yaml +4 -4
- data/Appraisals +3 -3
- data/CHANGELOG.md +881 -0
- data/CONTRIBUTING.md +11 -9
- data/Dangerfile +2 -2
- data/Dockerfile +29 -0
- data/Gemfile +4 -3
- data/NEWS.md +1 -814
- data/README.md +11 -3
- data/RELEASING.md +6 -5
- data/app/controllers/doorkeeper/application_controller.rb +2 -2
- data/app/controllers/doorkeeper/application_metal_controller.rb +3 -2
- data/app/controllers/doorkeeper/applications_controller.rb +1 -0
- data/app/controllers/doorkeeper/authorizations_controller.rb +16 -9
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +2 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +32 -9
- data/app/views/doorkeeper/applications/_form.html.erb +0 -6
- data/app/views/doorkeeper/applications/show.html.erb +1 -1
- data/config/locales/en.yml +8 -2
- data/doorkeeper.gemspec +9 -1
- data/gemfiles/rails_5_0.gemfile +3 -2
- data/gemfiles/rails_5_1.gemfile +3 -2
- data/gemfiles/rails_5_2.gemfile +3 -2
- data/gemfiles/rails_6_0.gemfile +4 -3
- data/gemfiles/rails_master.gemfile +3 -2
- data/lib/doorkeeper/config/option.rb +13 -7
- data/lib/doorkeeper/config.rb +157 -42
- data/lib/doorkeeper/errors.rb +13 -18
- data/lib/doorkeeper/grape/helpers.rb +6 -2
- data/lib/doorkeeper/helpers/controller.rb +28 -7
- data/lib/doorkeeper/models/access_grant_mixin.rb +7 -6
- data/lib/doorkeeper/models/access_token_mixin.rb +99 -20
- data/lib/doorkeeper/models/application_mixin.rb +3 -3
- data/lib/doorkeeper/models/concerns/ownership.rb +1 -1
- data/lib/doorkeeper/models/concerns/reusable.rb +1 -1
- data/lib/doorkeeper/models/concerns/revocable.rb +0 -27
- data/lib/doorkeeper/oauth/authorization/code.rb +12 -14
- data/lib/doorkeeper/oauth/authorization/token.rb +10 -7
- data/lib/doorkeeper/oauth/authorization_code_request.rb +31 -15
- data/lib/doorkeeper/oauth/base_request.rb +10 -4
- data/lib/doorkeeper/oauth/client.rb +7 -8
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +23 -2
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +7 -7
- data/lib/doorkeeper/oauth/client_credentials/{validation.rb → validator.rb} +10 -2
- data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -1
- data/lib/doorkeeper/oauth/code_request.rb +5 -11
- data/lib/doorkeeper/oauth/code_response.rb +4 -4
- data/lib/doorkeeper/oauth/error.rb +1 -1
- data/lib/doorkeeper/oauth/error_response.rb +6 -6
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +7 -5
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +8 -5
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +19 -5
- data/lib/doorkeeper/oauth/invalid_request_response.rb +43 -0
- data/lib/doorkeeper/oauth/invalid_token_response.rb +5 -2
- data/lib/doorkeeper/oauth/nonstandard.rb +39 -0
- data/lib/doorkeeper/oauth/password_access_token_request.rb +9 -4
- data/lib/doorkeeper/oauth/pre_authorization.rb +76 -38
- data/lib/doorkeeper/oauth/refresh_token_request.rb +17 -14
- data/lib/doorkeeper/oauth/token.rb +2 -2
- data/lib/doorkeeper/oauth/token_introspection.rb +26 -16
- data/lib/doorkeeper/oauth/token_request.rb +4 -18
- data/lib/doorkeeper/orm/active_record/access_grant.rb +4 -43
- data/lib/doorkeeper/orm/active_record/access_token.rb +4 -35
- data/lib/doorkeeper/orm/active_record/application.rb +5 -83
- data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +53 -0
- data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +47 -0
- data/lib/doorkeeper/orm/active_record/mixins/application.rb +128 -0
- data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +61 -0
- data/lib/doorkeeper/orm/active_record.rb +21 -6
- data/lib/doorkeeper/rails/helpers.rb +4 -4
- data/lib/doorkeeper/rails/routes.rb +5 -7
- data/lib/doorkeeper/rake/db.rake +3 -3
- data/lib/doorkeeper/request/authorization_code.rb +5 -3
- data/lib/doorkeeper/request/client_credentials.rb +2 -2
- data/lib/doorkeeper/request/password.rb +2 -2
- data/lib/doorkeeper/request/refresh_token.rb +3 -3
- data/lib/doorkeeper/request.rb +7 -12
- data/lib/doorkeeper/server.rb +3 -7
- data/lib/doorkeeper/stale_records_cleaner.rb +6 -2
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/doorkeeper.rb +6 -3
- data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +1 -1
- data/lib/generators/doorkeeper/migration_generator.rb +1 -1
- data/lib/generators/doorkeeper/pkce_generator.rb +1 -1
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +7 -7
- data/lib/generators/doorkeeper/templates/initializer.rb +149 -33
- data/lib/generators/doorkeeper/templates/migration.rb.erb +4 -1
- data/spec/controllers/application_metal_controller_spec.rb +1 -1
- data/spec/controllers/applications_controller_spec.rb +95 -1
- data/spec/controllers/authorizations_controller_spec.rb +156 -75
- data/spec/controllers/protected_resources_controller_spec.rb +28 -20
- data/spec/controllers/token_info_controller_spec.rb +1 -1
- data/spec/controllers/tokens_controller_spec.rb +206 -38
- data/spec/dummy/config/application.rb +3 -1
- data/spec/dummy/config/initializers/doorkeeper.rb +54 -9
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +3 -3
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +1 -1
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +1 -1
- data/spec/generators/install_generator_spec.rb +1 -1
- data/spec/generators/previous_refresh_token_generator_spec.rb +2 -2
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
- data/spec/lib/config_spec.rb +104 -7
- data/spec/lib/doorkeeper_spec.rb +1 -1
- data/spec/lib/models/revocable_spec.rb +3 -3
- data/spec/lib/oauth/authorization_code_request_spec.rb +129 -115
- data/spec/lib/oauth/base_request_spec.rb +154 -135
- data/spec/lib/oauth/base_response_spec.rb +27 -29
- data/spec/lib/oauth/client/credentials_spec.rb +1 -1
- data/spec/lib/oauth/client_credentials/creator_spec.rb +43 -3
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +12 -12
- data/spec/lib/oauth/client_credentials/validation_spec.rb +4 -4
- data/spec/lib/oauth/client_credentials_integration_spec.rb +16 -18
- data/spec/lib/oauth/client_credentials_request_spec.rb +78 -80
- data/spec/lib/oauth/client_spec.rb +26 -26
- data/spec/lib/oauth/code_request_spec.rb +34 -35
- data/spec/lib/oauth/code_response_spec.rb +21 -25
- data/spec/lib/oauth/error_response_spec.rb +42 -44
- data/spec/lib/oauth/error_spec.rb +12 -14
- data/spec/lib/oauth/forbidden_token_response_spec.rb +11 -13
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +30 -18
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +17 -2
- data/spec/lib/oauth/invalid_request_response_spec.rb +73 -0
- data/spec/lib/oauth/invalid_token_response_spec.rb +32 -34
- data/spec/lib/oauth/password_access_token_request_spec.rb +145 -147
- data/spec/lib/oauth/pre_authorization_spec.rb +161 -153
- data/spec/lib/oauth/refresh_token_request_spec.rb +138 -138
- data/spec/lib/oauth/scopes_spec.rb +104 -106
- data/spec/lib/oauth/token_request_spec.rb +117 -110
- data/spec/lib/oauth/token_response_spec.rb +71 -73
- data/spec/lib/oauth/token_spec.rb +121 -123
- data/spec/lib/server_spec.rb +0 -12
- data/spec/models/doorkeeper/access_grant_spec.rb +21 -4
- data/spec/models/doorkeeper/access_token_spec.rb +42 -11
- data/spec/models/doorkeeper/application_spec.rb +114 -77
- data/spec/requests/applications/applications_request_spec.rb +1 -1
- data/spec/requests/endpoints/authorization_spec.rb +26 -8
- data/spec/requests/endpoints/token_spec.rb +1 -1
- data/spec/requests/flows/authorization_code_errors_spec.rb +1 -0
- data/spec/requests/flows/authorization_code_spec.rb +123 -45
- data/spec/requests/flows/client_credentials_spec.rb +38 -0
- data/spec/requests/flows/implicit_grant_errors_spec.rb +22 -10
- data/spec/requests/flows/implicit_grant_spec.rb +9 -8
- data/spec/requests/flows/password_spec.rb +67 -10
- data/spec/requests/flows/refresh_token_spec.rb +20 -20
- data/spec/requests/flows/revoke_token_spec.rb +37 -23
- data/spec/spec_helper.rb +1 -4
- data/spec/support/doorkeeper_rspec.rb +1 -1
- data/spec/support/helpers/request_spec_helper.rb +14 -2
- data/spec/support/shared/controllers_shared_context.rb +33 -23
- data/spec/validators/redirect_uri_validator_spec.rb +41 -16
- metadata +19 -16
- data/.coveralls.yml +0 -1
- data/.github/ISSUE_TEMPLATE.md +0 -25
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -17
- data/.gitignore +0 -20
- data/.gitlab-ci.yml +0 -16
- data/.hound.yml +0 -3
- data/.rspec +0 -1
- data/.rubocop.yml +0 -50
- data/.travis.yml +0 -35
- data/app/validators/redirect_uri_validator.rb +0 -50
- data/spec/support/http_method_shim.rb +0 -29
|
@@ -14,23 +14,23 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
def translated_error_message(key)
|
|
18
|
-
I18n.translate key, scope: %i[doorkeeper errors messages]
|
|
19
|
-
end
|
|
20
|
-
|
|
21
17
|
let(:client) { FactoryBot.create :application }
|
|
22
18
|
let(:user) { User.create!(name: "Joe", password: "sekret") }
|
|
23
|
-
let(:access_token) { FactoryBot.build :access_token, resource_owner_id: user.id, application_id: client.id }
|
|
19
|
+
let(:access_token) { FactoryBot.build :access_token, resource_owner_id: user.id, application_id: client.id, scopes: "default" }
|
|
24
20
|
|
|
25
21
|
before do
|
|
26
22
|
Doorkeeper.configure do
|
|
23
|
+
default_scopes :default
|
|
24
|
+
|
|
27
25
|
custom_access_token_expires_in(lambda do |context|
|
|
28
26
|
context.grant_type == Doorkeeper::OAuth::IMPLICIT ? 1234 : nil
|
|
29
27
|
end)
|
|
30
28
|
end
|
|
31
29
|
|
|
32
|
-
allow(Doorkeeper.
|
|
33
|
-
allow(
|
|
30
|
+
allow(Doorkeeper.config).to receive(:grant_flows).and_return(["implicit"])
|
|
31
|
+
allow(Doorkeeper.config).to receive(:authenticate_resource_owner).and_return(->(_) { authenticator_method })
|
|
32
|
+
allow(controller).to receive(:authenticator_method).and_return(user)
|
|
33
|
+
expect(controller).to receive(:authenticator_method).at_most(:once)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
describe "POST #create" do
|
|
@@ -69,7 +69,7 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
|
69
69
|
|
|
70
70
|
describe "POST #create in API mode" do
|
|
71
71
|
before do
|
|
72
|
-
allow(Doorkeeper.
|
|
72
|
+
allow(Doorkeeper.config).to receive(:api_only).and_return(true)
|
|
73
73
|
post :create, params: { client_id: client.uid, response_type: "token", redirect_uri: client.redirect_uri }
|
|
74
74
|
end
|
|
75
75
|
|
|
@@ -106,86 +106,152 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
describe "POST #create with errors" do
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
context "when missing client_id" do
|
|
110
|
+
before do
|
|
111
|
+
post :create, params: {
|
|
112
|
+
client_id: "",
|
|
113
|
+
response_type: "token",
|
|
114
|
+
redirect_uri: client.redirect_uri,
|
|
115
|
+
}
|
|
116
|
+
end
|
|
111
117
|
|
|
112
|
-
|
|
113
|
-
client_id: client.uid,
|
|
114
|
-
response_type: "token",
|
|
115
|
-
scope: "invalid",
|
|
116
|
-
redirect_uri: client.redirect_uri,
|
|
117
|
-
}
|
|
118
|
-
end
|
|
118
|
+
let(:response_json_body) { JSON.parse(response.body) }
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
it "renders 400 error" do
|
|
121
|
+
expect(response.status).to eq 400
|
|
122
|
+
end
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
it "includes error name" do
|
|
125
|
+
expect(response_json_body["error"]).to eq("invalid_request")
|
|
126
|
+
end
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
it "includes error description" do
|
|
129
|
+
expect(response_json_body["error_description"]).to eq(
|
|
130
|
+
translated_invalid_request_error_message(:missing_param, :client_id),
|
|
131
|
+
)
|
|
132
|
+
end
|
|
131
133
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
it "does not issue any access token" do
|
|
135
|
+
expect(Doorkeeper::AccessToken.all).to be_empty
|
|
136
|
+
end
|
|
134
137
|
end
|
|
135
138
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
+
context "when other error happens" do
|
|
140
|
+
before do
|
|
141
|
+
default_scopes_exist :public
|
|
142
|
+
|
|
143
|
+
post :create, params: {
|
|
144
|
+
client_id: client.uid,
|
|
145
|
+
response_type: "token",
|
|
146
|
+
scope: "invalid",
|
|
147
|
+
redirect_uri: client.redirect_uri,
|
|
148
|
+
}
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "redirects after authorization" do
|
|
152
|
+
expect(response).to be_redirect
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
it "redirects to client redirect uri" do
|
|
156
|
+
expect(response.location).to match(/^#{client.redirect_uri}/)
|
|
157
|
+
end
|
|
139
158
|
|
|
140
|
-
|
|
141
|
-
|
|
159
|
+
it "does not include access token in fragment" do
|
|
160
|
+
expect(response.query_params["access_token"]).to be_nil
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it "includes error in fragment" do
|
|
164
|
+
expect(response.query_params["error"]).to eq("invalid_scope")
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
it "includes error description in fragment" do
|
|
168
|
+
expect(response.query_params["error_description"]).to eq(translated_error_message(:invalid_scope))
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it "does not issue any access token" do
|
|
172
|
+
expect(Doorkeeper::AccessToken.all).to be_empty
|
|
173
|
+
end
|
|
142
174
|
end
|
|
143
175
|
end
|
|
144
176
|
|
|
145
177
|
describe "POST #create in API mode with errors" do
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
178
|
+
context "when missing client_id" do
|
|
179
|
+
before do
|
|
180
|
+
allow(Doorkeeper.config).to receive(:api_only).and_return(true)
|
|
149
181
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
end
|
|
182
|
+
post :create, params: {
|
|
183
|
+
client_id: "",
|
|
184
|
+
response_type: "token",
|
|
185
|
+
redirect_uri: client.redirect_uri,
|
|
186
|
+
}
|
|
187
|
+
end
|
|
157
188
|
|
|
158
|
-
|
|
159
|
-
let(:redirect_uri) { response_json_body["redirect_uri"] }
|
|
189
|
+
let(:response_json_body) { JSON.parse(response.body) }
|
|
160
190
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
191
|
+
it "renders 400 error" do
|
|
192
|
+
expect(response.status).to eq 400
|
|
193
|
+
end
|
|
164
194
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
195
|
+
it "includes error name" do
|
|
196
|
+
expect(response_json_body["error"]).to eq("invalid_request")
|
|
197
|
+
end
|
|
168
198
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
199
|
+
it "includes error description" do
|
|
200
|
+
expect(response_json_body["error_description"]).to eq(
|
|
201
|
+
translated_invalid_request_error_message(:missing_param, :client_id),
|
|
202
|
+
)
|
|
203
|
+
end
|
|
172
204
|
|
|
173
|
-
|
|
174
|
-
|
|
205
|
+
it "does not issue any access token" do
|
|
206
|
+
expect(Doorkeeper::AccessToken.all).to be_empty
|
|
207
|
+
end
|
|
175
208
|
end
|
|
176
209
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
210
|
+
context "when other error happens" do
|
|
211
|
+
before do
|
|
212
|
+
allow(Doorkeeper.config).to receive(:api_only).and_return(true)
|
|
213
|
+
default_scopes_exist :public
|
|
214
|
+
|
|
215
|
+
post :create, params: {
|
|
216
|
+
client_id: client.uid,
|
|
217
|
+
response_type: "token",
|
|
218
|
+
scope: "invalid",
|
|
219
|
+
redirect_uri: client.redirect_uri,
|
|
220
|
+
}
|
|
221
|
+
end
|
|
180
222
|
|
|
181
|
-
|
|
182
|
-
|
|
223
|
+
let(:response_json_body) { JSON.parse(response.body) }
|
|
224
|
+
let(:redirect_uri) { response_json_body["redirect_uri"] }
|
|
225
|
+
|
|
226
|
+
it "renders 400 error" do
|
|
227
|
+
expect(response.status).to eq 400
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it "includes correct redirect URI" do
|
|
231
|
+
expect(redirect_uri).to match(/^#{client.redirect_uri}/)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
it "does not include access token in fragment" do
|
|
235
|
+
expect(redirect_uri.match(/access_token=([a-f0-9]+)&?/)).to be_nil
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
it "includes error in redirect uri" do
|
|
239
|
+
expect(redirect_uri.match(/error=([a-z_]+)&?/)[1]).to eq "invalid_scope"
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
it "includes error description in redirect uri" do
|
|
243
|
+
expect(redirect_uri.match(/error_description=(.+)&?/)[1]).to_not be_nil
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
it "does not issue any access token" do
|
|
247
|
+
expect(Doorkeeper::AccessToken.all).to be_empty
|
|
248
|
+
end
|
|
183
249
|
end
|
|
184
250
|
end
|
|
185
251
|
|
|
186
252
|
describe "POST #create with application already authorized" do
|
|
187
253
|
before do
|
|
188
|
-
allow(Doorkeeper.
|
|
254
|
+
allow(Doorkeeper.config).to receive(:reuse_access_token).and_return(true)
|
|
189
255
|
|
|
190
256
|
access_token.save!
|
|
191
257
|
|
|
@@ -220,12 +286,12 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
|
220
286
|
end
|
|
221
287
|
|
|
222
288
|
it "should call :before_successful_authorization callback" do
|
|
223
|
-
expect(Doorkeeper.
|
|
289
|
+
expect(Doorkeeper.config)
|
|
224
290
|
.to receive_message_chain(:before_successful_authorization, :call).with(instance_of(described_class))
|
|
225
291
|
end
|
|
226
292
|
|
|
227
293
|
it "should call :after_successful_authorization callback" do
|
|
228
|
-
expect(Doorkeeper.
|
|
294
|
+
expect(Doorkeeper.config)
|
|
229
295
|
.to receive_message_chain(:after_successful_authorization, :call).with(instance_of(described_class))
|
|
230
296
|
end
|
|
231
297
|
end
|
|
@@ -236,18 +302,18 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
|
236
302
|
end
|
|
237
303
|
|
|
238
304
|
it "should not call :before_successful_authorization callback" do
|
|
239
|
-
expect(Doorkeeper.
|
|
305
|
+
expect(Doorkeeper.config).not_to receive(:before_successful_authorization)
|
|
240
306
|
end
|
|
241
307
|
|
|
242
308
|
it "should not call :after_successful_authorization callback" do
|
|
243
|
-
expect(Doorkeeper.
|
|
309
|
+
expect(Doorkeeper.config).not_to receive(:after_successful_authorization)
|
|
244
310
|
end
|
|
245
311
|
end
|
|
246
312
|
end
|
|
247
313
|
|
|
248
314
|
describe "GET #new token request with native url and skip_authorization true" do
|
|
249
315
|
before do
|
|
250
|
-
allow(Doorkeeper.
|
|
316
|
+
allow(Doorkeeper.config).to receive(:skip_authorization).and_return(proc do
|
|
251
317
|
true
|
|
252
318
|
end)
|
|
253
319
|
|
|
@@ -276,8 +342,8 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
|
276
342
|
|
|
277
343
|
describe "GET #new code request with native url and skip_authorization true" do
|
|
278
344
|
before do
|
|
279
|
-
allow(Doorkeeper.
|
|
280
|
-
allow(Doorkeeper.
|
|
345
|
+
allow(Doorkeeper.config).to receive(:grant_flows).and_return(%w[authorization_code])
|
|
346
|
+
allow(Doorkeeper.config).to receive(:skip_authorization).and_return(proc do
|
|
281
347
|
true
|
|
282
348
|
end)
|
|
283
349
|
|
|
@@ -307,7 +373,7 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
|
307
373
|
|
|
308
374
|
describe "GET #new with skip_authorization true" do
|
|
309
375
|
before do
|
|
310
|
-
allow(Doorkeeper.
|
|
376
|
+
allow(Doorkeeper.config).to receive(:skip_authorization).and_return(proc do
|
|
311
377
|
true
|
|
312
378
|
end)
|
|
313
379
|
|
|
@@ -346,7 +412,7 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
|
346
412
|
|
|
347
413
|
describe "GET #new in API mode" do
|
|
348
414
|
before do
|
|
349
|
-
allow(Doorkeeper.
|
|
415
|
+
allow(Doorkeeper.config).to receive(:api_only).and_return(true)
|
|
350
416
|
|
|
351
417
|
get :new, params: {
|
|
352
418
|
client_id: client.uid,
|
|
@@ -368,7 +434,7 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
|
368
434
|
expect(json_response["redirect_uri"]).to eq(client.redirect_uri)
|
|
369
435
|
expect(json_response["state"]).to be_nil
|
|
370
436
|
expect(json_response["response_type"]).to eq("token")
|
|
371
|
-
expect(json_response["scope"]).to eq("")
|
|
437
|
+
expect(json_response["scope"]).to eq("default")
|
|
372
438
|
end
|
|
373
439
|
end
|
|
374
440
|
|
|
@@ -402,7 +468,7 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
|
402
468
|
expect(redirect_uri.match(/token_type=(\w+)&?/)[1]).to eq "Bearer"
|
|
403
469
|
expect(redirect_uri.match(/expires_in=(\d+)&?/)[1].to_i).to eq 1234
|
|
404
470
|
expect(
|
|
405
|
-
redirect_uri.match(/access_token=([a-zA-Z0-9\-_]+)&?/)[1]
|
|
471
|
+
redirect_uri.match(/access_token=([a-zA-Z0-9\-_]+)&?/)[1],
|
|
406
472
|
).to eq Doorkeeper::AccessToken.first.token
|
|
407
473
|
end
|
|
408
474
|
|
|
@@ -445,12 +511,12 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
|
445
511
|
end
|
|
446
512
|
|
|
447
513
|
it "includes error in body" do
|
|
448
|
-
expect(response_json_body["error"]).to eq("
|
|
514
|
+
expect(response_json_body["error"]).to eq("invalid_request")
|
|
449
515
|
end
|
|
450
516
|
|
|
451
517
|
it "includes error description in body" do
|
|
452
518
|
expect(response_json_body["error_description"])
|
|
453
|
-
.to eq(
|
|
519
|
+
.to eq(translated_invalid_request_error_message(:missing_param, :client_id))
|
|
454
520
|
end
|
|
455
521
|
|
|
456
522
|
it "does not issue any token" do
|
|
@@ -513,6 +579,8 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
|
513
579
|
|
|
514
580
|
describe "authorize response memoization" do
|
|
515
581
|
it "memoizes the result of the authorization" do
|
|
582
|
+
pre_auth = double(:pre_auth, authorizable?: true)
|
|
583
|
+
allow(controller).to receive(:pre_auth) { pre_auth }
|
|
516
584
|
strategy = double(:strategy, authorize: true)
|
|
517
585
|
expect(strategy).to receive(:authorize).once
|
|
518
586
|
allow(controller).to receive(:strategy) { strategy }
|
|
@@ -524,4 +592,17 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
|
|
|
524
592
|
post :create
|
|
525
593
|
end
|
|
526
594
|
end
|
|
595
|
+
|
|
596
|
+
describe "strong parameters" do
|
|
597
|
+
it "ignores non-scalar scope parameter" do
|
|
598
|
+
get :new, params: {
|
|
599
|
+
client_id: client.uid,
|
|
600
|
+
response_type: "token",
|
|
601
|
+
redirect_uri: client.redirect_uri,
|
|
602
|
+
scope: { "0" => "profile" },
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
expect(response).to be_successful
|
|
606
|
+
end
|
|
607
|
+
end
|
|
527
608
|
end
|
|
@@ -28,9 +28,11 @@ describe "doorkeeper authorize filter" do
|
|
|
28
28
|
|
|
29
29
|
let(:token_string) { "1A2BC3" }
|
|
30
30
|
let(:token) do
|
|
31
|
-
double(
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
double(
|
|
32
|
+
Doorkeeper::AccessToken,
|
|
33
|
+
acceptable?: true, previous_refresh_token: "",
|
|
34
|
+
revoke_previous_refresh_token!: true,
|
|
35
|
+
)
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
it "access_token param" do
|
|
@@ -108,13 +110,15 @@ describe "doorkeeper authorize filter" do
|
|
|
108
110
|
let(:token_string) { "1A2DUWE" }
|
|
109
111
|
|
|
110
112
|
it "allows if the token has particular scopes" do
|
|
111
|
-
token = double(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
token = double(
|
|
114
|
+
Doorkeeper::AccessToken,
|
|
115
|
+
accessible?: true, scopes: %w[write public],
|
|
116
|
+
previous_refresh_token: "",
|
|
117
|
+
revoke_previous_refresh_token!: true,
|
|
118
|
+
)
|
|
115
119
|
expect(token).to receive(:acceptable?).with([:write]).and_return(true)
|
|
116
120
|
expect(
|
|
117
|
-
Doorkeeper::AccessToken
|
|
121
|
+
Doorkeeper::AccessToken,
|
|
118
122
|
).to receive(:by_token).with(token_string).and_return(token)
|
|
119
123
|
|
|
120
124
|
get :index, params: { access_token: token_string }
|
|
@@ -122,12 +126,14 @@ describe "doorkeeper authorize filter" do
|
|
|
122
126
|
end
|
|
123
127
|
|
|
124
128
|
it "does not allow if the token does not include given scope" do
|
|
125
|
-
token = double(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
token = double(
|
|
130
|
+
Doorkeeper::AccessToken,
|
|
131
|
+
accessible?: true, scopes: ["public"], revoked?: false,
|
|
132
|
+
expired?: false, previous_refresh_token: "",
|
|
133
|
+
revoke_previous_refresh_token!: true,
|
|
134
|
+
)
|
|
129
135
|
expect(
|
|
130
|
-
Doorkeeper::AccessToken
|
|
136
|
+
Doorkeeper::AccessToken,
|
|
131
137
|
).to receive(:by_token).with(token_string).and_return(token)
|
|
132
138
|
expect(token).to receive(:acceptable?).with([:write]).and_return(false)
|
|
133
139
|
|
|
@@ -166,7 +172,7 @@ describe "doorkeeper authorize filter" do
|
|
|
166
172
|
it "it renders a custom JSON response", token: :invalid do
|
|
167
173
|
get :index, params: { access_token: token_string }
|
|
168
174
|
expect(response.status).to eq 401
|
|
169
|
-
expect(response.content_type).to
|
|
175
|
+
expect(response.content_type).to include("application/json")
|
|
170
176
|
expect(response.header["WWW-Authenticate"]).to match(/^Bearer/)
|
|
171
177
|
|
|
172
178
|
expect(json_response).not_to be_nil
|
|
@@ -196,7 +202,7 @@ describe "doorkeeper authorize filter" do
|
|
|
196
202
|
it "it renders a custom text response", token: :invalid do
|
|
197
203
|
get :index, params: { access_token: token_string }
|
|
198
204
|
expect(response.status).to eq 401
|
|
199
|
-
expect(response.content_type).to
|
|
205
|
+
expect(response.content_type).to include("text/plain")
|
|
200
206
|
expect(response.header["WWW-Authenticate"]).to match(/^Bearer/)
|
|
201
207
|
expect(response.body).to eq("Unauthorized")
|
|
202
208
|
end
|
|
@@ -224,10 +230,12 @@ describe "doorkeeper authorize filter" do
|
|
|
224
230
|
end
|
|
225
231
|
|
|
226
232
|
let(:token) do
|
|
227
|
-
double(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
233
|
+
double(
|
|
234
|
+
Doorkeeper::AccessToken,
|
|
235
|
+
accessible?: true, scopes: ["public"], revoked?: false,
|
|
236
|
+
expired?: false, previous_refresh_token: "",
|
|
237
|
+
revoke_previous_refresh_token!: true,
|
|
238
|
+
)
|
|
231
239
|
end
|
|
232
240
|
|
|
233
241
|
let(:token_string) { "1A2DUWE" }
|
|
@@ -246,7 +254,7 @@ describe "doorkeeper authorize filter" do
|
|
|
246
254
|
it "renders a custom JSON response" do
|
|
247
255
|
get :index, params: { access_token: token_string }
|
|
248
256
|
expect(response.header).to_not include("WWW-Authenticate")
|
|
249
|
-
expect(response.content_type).to
|
|
257
|
+
expect(response.content_type).to include("application/json")
|
|
250
258
|
expect(response.status).to eq 403
|
|
251
259
|
|
|
252
260
|
expect(json_response).not_to be_nil
|