doorkeeper 4.4.3 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of doorkeeper might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitlab-ci.yml +16 -0
- data/.travis.yml +2 -0
- data/Appraisals +2 -2
- data/Gemfile +1 -1
- data/NEWS.md +61 -8
- data/README.md +92 -9
- data/Rakefile +6 -0
- data/UPGRADE.md +2 -0
- data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
- data/app/controllers/doorkeeper/application_controller.rb +4 -3
- data/app/controllers/doorkeeper/application_metal_controller.rb +4 -0
- data/app/controllers/doorkeeper/applications_controller.rb +42 -22
- data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +19 -2
- data/app/controllers/doorkeeper/tokens_controller.rb +2 -6
- data/app/helpers/doorkeeper/dashboard_helper.rb +7 -7
- data/app/validators/redirect_uri_validator.rb +3 -2
- data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
- data/app/views/doorkeeper/applications/_form.html.erb +25 -24
- data/app/views/doorkeeper/applications/edit.html.erb +1 -1
- data/app/views/doorkeeper/applications/index.html.erb +17 -7
- data/app/views/doorkeeper/applications/new.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +6 -6
- data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +4 -0
- data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
- data/config/locales/en.yml +10 -1
- data/doorkeeper.gemspec +18 -20
- data/gemfiles/rails_5_2.gemfile +1 -1
- data/gemfiles/rails_master.gemfile +4 -1
- data/lib/doorkeeper/config.rb +75 -39
- data/lib/doorkeeper/engine.rb +4 -0
- data/lib/doorkeeper/errors.rb +2 -5
- data/lib/doorkeeper/grape/helpers.rb +1 -1
- data/lib/doorkeeper/helpers/controller.rb +7 -2
- data/lib/doorkeeper/models/access_grant_mixin.rb +71 -0
- data/lib/doorkeeper/models/access_token_mixin.rb +39 -22
- data/lib/doorkeeper/models/concerns/scopes.rb +1 -1
- data/lib/doorkeeper/oauth/authorization/code.rb +31 -8
- data/lib/doorkeeper/oauth/authorization/context.rb +15 -0
- data/lib/doorkeeper/oauth/authorization/token.rb +36 -14
- data/lib/doorkeeper/oauth/authorization_code_request.rb +27 -2
- data/lib/doorkeeper/oauth/base_request.rb +20 -9
- data/lib/doorkeeper/oauth/client/credentials.rb +1 -1
- data/lib/doorkeeper/oauth/client.rb +0 -2
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +2 -1
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +6 -3
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +4 -6
- data/lib/doorkeeper/oauth/client_credentials_request.rb +0 -4
- data/lib/doorkeeper/oauth/error_response.rb +11 -3
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +0 -8
- data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -4
- data/lib/doorkeeper/oauth/pre_authorization.rb +41 -11
- data/lib/doorkeeper/oauth/refresh_token_request.rb +6 -1
- data/lib/doorkeeper/oauth/scopes.rb +1 -1
- data/lib/doorkeeper/oauth/token.rb +5 -2
- data/lib/doorkeeper/oauth/token_introspection.rb +2 -2
- data/lib/doorkeeper/oauth/token_response.rb +4 -2
- data/lib/doorkeeper/oauth.rb +13 -0
- data/lib/doorkeeper/orm/active_record/application.rb +22 -14
- data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
- data/lib/doorkeeper/orm/active_record.rb +2 -0
- data/lib/doorkeeper/rails/helpers.rb +2 -4
- data/lib/doorkeeper/rails/routes.rb +14 -6
- data/lib/doorkeeper/rake/db.rake +40 -0
- data/lib/doorkeeper/rake/setup.rake +6 -0
- data/lib/doorkeeper/rake.rb +14 -0
- data/lib/doorkeeper/request/authorization_code.rb +0 -2
- data/lib/doorkeeper/request/client_credentials.rb +0 -2
- data/lib/doorkeeper/request/code.rb +0 -2
- data/lib/doorkeeper/request/password.rb +0 -2
- data/lib/doorkeeper/request/refresh_token.rb +0 -2
- data/lib/doorkeeper/request/token.rb +0 -2
- data/lib/doorkeeper/request.rb +28 -35
- data/lib/doorkeeper/version.rb +5 -25
- data/lib/doorkeeper.rb +19 -17
- data/lib/generators/doorkeeper/application_owner_generator.rb +23 -18
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +32 -0
- data/lib/generators/doorkeeper/install_generator.rb +17 -9
- data/lib/generators/doorkeeper/migration_generator.rb +23 -18
- data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -24
- data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
- data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
- data/lib/generators/doorkeeper/templates/initializer.rb +76 -11
- data/lib/generators/doorkeeper/views_generator.rb +3 -1
- data/spec/controllers/application_metal_controller_spec.rb +50 -0
- data/spec/controllers/applications_controller_spec.rb +126 -13
- data/spec/controllers/authorizations_controller_spec.rb +277 -47
- data/spec/controllers/protected_resources_controller_spec.rb +16 -16
- data/spec/controllers/token_info_controller_spec.rb +4 -12
- data/spec/controllers/tokens_controller_spec.rb +13 -15
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/config/environments/test.rb +4 -5
- data/spec/dummy/config/initializers/doorkeeper.rb +10 -5
- data/spec/dummy/config/initializers/new_framework_defaults.rb +4 -0
- data/spec/dummy/config/routes.rb +3 -42
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
- data/spec/dummy/db/migrate/{20180210183654_add_confidential_to_application.rb → 20180210183654_add_confidential_to_applications.rb} +1 -1
- data/spec/dummy/db/schema.rb +36 -36
- data/spec/generators/application_owner_generator_spec.rb +1 -1
- data/spec/generators/confidential_applications_generator_spec.rb +45 -0
- data/spec/generators/install_generator_spec.rb +1 -1
- data/spec/generators/migration_generator_spec.rb +1 -1
- data/spec/generators/pkce_generator_spec.rb +43 -0
- data/spec/generators/previous_refresh_token_generator_spec.rb +1 -1
- data/spec/generators/views_generator_spec.rb +1 -1
- 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 +80 -31
- data/spec/lib/doorkeeper_spec.rb +1 -126
- data/spec/lib/models/expirable_spec.rb +0 -3
- data/spec/lib/models/revocable_spec.rb +0 -2
- data/spec/lib/models/scopes_spec.rb +0 -4
- data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -4
- data/spec/lib/oauth/authorization_code_request_spec.rb +9 -2
- data/spec/lib/oauth/base_request_spec.rb +40 -2
- data/spec/lib/oauth/base_response_spec.rb +1 -1
- data/spec/lib/oauth/client/credentials_spec.rb +1 -3
- data/spec/lib/oauth/client_credentials/creator_spec.rb +5 -1
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +26 -7
- data/spec/lib/oauth/client_credentials/validation_spec.rb +2 -3
- data/spec/lib/oauth/client_credentials_integration_spec.rb +1 -1
- data/spec/lib/oauth/client_credentials_request_spec.rb +3 -5
- data/spec/lib/oauth/client_spec.rb +0 -3
- data/spec/lib/oauth/code_request_spec.rb +4 -2
- data/spec/lib/oauth/error_response_spec.rb +0 -3
- data/spec/lib/oauth/error_spec.rb +0 -2
- data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +0 -3
- data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +5 -7
- data/spec/lib/oauth/invalid_token_response_spec.rb +1 -4
- data/spec/lib/oauth/password_access_token_request_spec.rb +37 -2
- data/spec/lib/oauth/pre_authorization_spec.rb +33 -4
- data/spec/lib/oauth/refresh_token_request_spec.rb +11 -7
- data/spec/lib/oauth/scopes_spec.rb +0 -3
- data/spec/lib/oauth/token_request_spec.rb +4 -5
- data/spec/lib/oauth/token_response_spec.rb +0 -1
- data/spec/lib/oauth/token_spec.rb +37 -14
- data/spec/lib/orm/active_record/stale_records_cleaner_spec.rb +79 -0
- data/spec/lib/request/strategy_spec.rb +0 -1
- data/spec/lib/server_spec.rb +1 -1
- data/spec/models/doorkeeper/access_grant_spec.rb +44 -1
- data/spec/models/doorkeeper/access_token_spec.rb +66 -22
- data/spec/models/doorkeeper/application_spec.rb +14 -47
- data/spec/requests/applications/applications_request_spec.rb +134 -1
- data/spec/requests/applications/authorized_applications_spec.rb +1 -1
- data/spec/requests/endpoints/authorization_spec.rb +1 -1
- data/spec/requests/endpoints/token_spec.rb +7 -5
- data/spec/requests/flows/authorization_code_errors_spec.rb +1 -1
- data/spec/requests/flows/authorization_code_spec.rb +197 -1
- data/spec/requests/flows/client_credentials_spec.rb +46 -6
- data/spec/requests/flows/implicit_grant_errors_spec.rb +1 -1
- data/spec/requests/flows/implicit_grant_spec.rb +38 -11
- data/spec/requests/flows/password_spec.rb +56 -2
- data/spec/requests/flows/refresh_token_spec.rb +2 -2
- data/spec/requests/flows/revoke_token_spec.rb +11 -11
- data/spec/requests/flows/skip_authorization_spec.rb +16 -11
- data/spec/requests/protected_resources/metal_spec.rb +1 -1
- data/spec/requests/protected_resources/private_api_spec.rb +1 -1
- data/spec/routing/custom_controller_routes_spec.rb +59 -7
- data/spec/routing/default_routes_spec.rb +2 -2
- data/spec/routing/scoped_routes_spec.rb +16 -2
- data/spec/spec_helper.rb +54 -3
- data/spec/spec_helper_integration.rb +2 -74
- data/spec/support/dependencies/{factory_girl.rb → factory_bot.rb} +0 -0
- data/spec/support/doorkeeper_rspec.rb +19 -0
- data/spec/support/helpers/authorization_request_helper.rb +4 -4
- data/spec/support/helpers/request_spec_helper.rb +10 -2
- data/spec/support/helpers/url_helper.rb +7 -3
- data/spec/support/http_method_shim.rb +12 -16
- data/spec/validators/redirect_uri_validator_spec.rb +7 -1
- data/spec/version/version_spec.rb +3 -3
- data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
- metadata +37 -33
- data/lib/generators/doorkeeper/add_client_confidentiality_generator.rb +0 -31
- data/lib/generators/doorkeeper/templates/add_confidential_to_application_migration.rb.erb +0 -11
- data/spec/controllers/application_metal_controller.rb +0 -10
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module ControllerActions
|
4
4
|
def index
|
@@ -33,12 +33,12 @@ describe 'doorkeeper authorize filter' do
|
|
33
33
|
|
34
34
|
it 'access_token param' do
|
35
35
|
expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
|
36
|
-
get :index, access_token: token_string
|
36
|
+
get :index, params: { access_token: token_string }
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'bearer_token param' do
|
40
40
|
expect(Doorkeeper::AccessToken).to receive(:by_token).with(token_string).and_return(token)
|
41
|
-
get :index, bearer_token: token_string
|
41
|
+
get :index, params: { bearer_token: token_string }
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'Authorization header' do
|
@@ -57,7 +57,7 @@ describe 'doorkeeper authorize filter' do
|
|
57
57
|
expect(Doorkeeper::AccessToken).to receive(:by_token).exactly(2).times.and_return(token)
|
58
58
|
request.env['HTTP_AUTHORIZATION'] = "Bearer #{token_string}"
|
59
59
|
get :index
|
60
|
-
controller.send(:remove_instance_variable, :@
|
60
|
+
controller.send(:remove_instance_variable, :@doorkeeper_token)
|
61
61
|
get :index
|
62
62
|
end
|
63
63
|
end
|
@@ -71,25 +71,25 @@ describe 'doorkeeper authorize filter' do
|
|
71
71
|
|
72
72
|
context 'with valid token', token: :valid do
|
73
73
|
it 'allows into index action' do
|
74
|
-
get :index, access_token: token_string
|
74
|
+
get :index, params: { access_token: token_string }
|
75
75
|
expect(response).to be_successful
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'allows into show action' do
|
79
|
-
get :show, id: '4', access_token: token_string
|
79
|
+
get :show, params: { id: '4', access_token: token_string }
|
80
80
|
expect(response).to be_successful
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
context 'with invalid token', token: :invalid do
|
85
85
|
it 'does not allow into index action' do
|
86
|
-
get :index, access_token: token_string
|
86
|
+
get :index, params: { access_token: token_string }
|
87
87
|
expect(response.status).to eq 401
|
88
88
|
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
89
89
|
end
|
90
90
|
|
91
91
|
it 'does not allow into show action' do
|
92
|
-
get :show, id: '4', access_token: token_string
|
92
|
+
get :show, params: { id: '4', access_token: token_string }
|
93
93
|
expect(response.status).to eq 401
|
94
94
|
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
95
95
|
end
|
@@ -115,7 +115,7 @@ describe 'doorkeeper authorize filter' do
|
|
115
115
|
Doorkeeper::AccessToken
|
116
116
|
).to receive(:by_token).with(token_string).and_return(token)
|
117
117
|
|
118
|
-
get :index, access_token: token_string
|
118
|
+
get :index, params: { access_token: token_string }
|
119
119
|
expect(response).to be_successful
|
120
120
|
end
|
121
121
|
|
@@ -129,7 +129,7 @@ describe 'doorkeeper authorize filter' do
|
|
129
129
|
).to receive(:by_token).with(token_string).and_return(token)
|
130
130
|
expect(token).to receive(:acceptable?).with([:write]).and_return(false)
|
131
131
|
|
132
|
-
get :index, access_token: token_string
|
132
|
+
get :index, params: { access_token: token_string }
|
133
133
|
expect(response.status).to eq 403
|
134
134
|
expect(response.header).to_not include('WWW-Authenticate')
|
135
135
|
end
|
@@ -163,7 +163,7 @@ describe 'doorkeeper authorize filter' do
|
|
163
163
|
end
|
164
164
|
|
165
165
|
it 'it renders a custom JSON response', token: :invalid do
|
166
|
-
get :index, access_token: token_string
|
166
|
+
get :index, params: { access_token: token_string }
|
167
167
|
expect(response.status).to eq 401
|
168
168
|
expect(response.content_type).to eq('application/json')
|
169
169
|
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
@@ -193,7 +193,7 @@ describe 'doorkeeper authorize filter' do
|
|
193
193
|
end
|
194
194
|
|
195
195
|
it 'it renders a custom text response', token: :invalid do
|
196
|
-
get :index, access_token: token_string
|
196
|
+
get :index, params: { access_token: token_string }
|
197
197
|
expect(response.status).to eq 401
|
198
198
|
expect(response.content_type).to eq('text/plain')
|
199
199
|
expect(response.header['WWW-Authenticate']).to match(/^Bearer/)
|
@@ -243,7 +243,7 @@ describe 'doorkeeper authorize filter' do
|
|
243
243
|
end
|
244
244
|
|
245
245
|
it 'renders a custom JSON response' do
|
246
|
-
get :index, access_token: token_string
|
246
|
+
get :index, params: { access_token: token_string }
|
247
247
|
expect(response.header).to_not include('WWW-Authenticate')
|
248
248
|
expect(response.content_type).to eq('application/json')
|
249
249
|
expect(response.status).to eq 403
|
@@ -265,7 +265,7 @@ describe 'doorkeeper authorize filter' do
|
|
265
265
|
end
|
266
266
|
|
267
267
|
it 'overrides the default status code' do
|
268
|
-
get :index, access_token: token_string
|
268
|
+
get :index, params: { access_token: token_string }
|
269
269
|
expect(response.status).to eq 404
|
270
270
|
end
|
271
271
|
end
|
@@ -282,7 +282,7 @@ describe 'doorkeeper authorize filter' do
|
|
282
282
|
end
|
283
283
|
|
284
284
|
it 'renders a custom status code and text response' do
|
285
|
-
get :index, access_token: token_string
|
285
|
+
get :index, params: { access_token: token_string }
|
286
286
|
expect(response.header).to_not include('WWW-Authenticate')
|
287
287
|
expect(response.status).to eq 403
|
288
288
|
expect(response.body).to eq('Forbidden')
|
@@ -301,7 +301,7 @@ describe 'doorkeeper authorize filter' do
|
|
301
301
|
end
|
302
302
|
|
303
303
|
it 'overrides the default status code' do
|
304
|
-
get :index, access_token: token_string
|
304
|
+
get :index, params: { access_token: token_string }
|
305
305
|
expect(response.status).to eq 404
|
306
306
|
end
|
307
307
|
end
|
@@ -1,32 +1,24 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Doorkeeper::TokenInfoController do
|
4
4
|
describe 'when requesting token info with valid token' do
|
5
5
|
let(:doorkeeper_token) { FactoryBot.create(:access_token) }
|
6
6
|
|
7
|
-
before(:each) do
|
8
|
-
allow(controller).to receive(:doorkeeper_token) { doorkeeper_token }
|
9
|
-
end
|
10
|
-
|
11
7
|
describe 'successful request' do
|
12
|
-
it 'responds with
|
13
|
-
get :show
|
8
|
+
it 'responds with token info' do
|
9
|
+
get :show, params: { access_token: doorkeeper_token.token }
|
14
10
|
|
15
11
|
expect(response.body).to eq(doorkeeper_token.to_json)
|
16
12
|
end
|
17
13
|
|
18
14
|
it 'responds with a 200 status' do
|
19
|
-
get :show
|
15
|
+
get :show, params: { access_token: doorkeeper_token.token }
|
20
16
|
|
21
17
|
expect(response.status).to eq 200
|
22
18
|
end
|
23
19
|
end
|
24
20
|
|
25
21
|
describe 'invalid token response' do
|
26
|
-
before(:each) do
|
27
|
-
allow(controller).to receive(:doorkeeper_token).and_return(nil)
|
28
|
-
end
|
29
|
-
|
30
22
|
it 'responds with 401 when doorkeeper_token is not valid' do
|
31
23
|
get :show
|
32
24
|
|
@@ -1,12 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Doorkeeper::TokensController do
|
4
4
|
describe 'when authorization has succeeded' do
|
5
5
|
let(:token) { double(:token, authorize: true) }
|
6
6
|
|
7
|
-
before do
|
8
|
-
allow(controller).to receive(:token) { token }
|
9
|
-
end
|
10
7
|
|
11
8
|
it 'returns the authorization' do
|
12
9
|
skip 'verify need of these specs'
|
@@ -36,7 +33,7 @@ describe Doorkeeper::TokensController do
|
|
36
33
|
allow(I18n).to receive(:translate).
|
37
34
|
with(
|
38
35
|
custom_message,
|
39
|
-
hash_including(scope: %i[doorkeeper errors messages])
|
36
|
+
hash_including(scope: %i[doorkeeper errors messages])
|
40
37
|
).
|
41
38
|
and_return('Authorization custom message')
|
42
39
|
|
@@ -129,7 +126,8 @@ describe Doorkeeper::TokensController do
|
|
129
126
|
expect(strategy).to receive(:authorize).once
|
130
127
|
allow(controller).to receive(:strategy) { strategy }
|
131
128
|
allow(controller).to receive(:create) do
|
132
|
-
controller.send :authorize_response
|
129
|
+
2.times { controller.send :authorize_response }
|
130
|
+
controller.render json: {}, status: :ok
|
133
131
|
end
|
134
132
|
|
135
133
|
post :create
|
@@ -144,7 +142,7 @@ describe Doorkeeper::TokensController do
|
|
144
142
|
it 'responds with full token introspection' do
|
145
143
|
request.headers['Authorization'] = "Bearer #{access_token.token}"
|
146
144
|
|
147
|
-
post :introspect, token: access_token.token
|
145
|
+
post :introspect, params: { token: access_token.token }
|
148
146
|
|
149
147
|
should_have_json 'active', true
|
150
148
|
expect(json_response).to include('client_id', 'token_type', 'exp', 'iat')
|
@@ -158,7 +156,7 @@ describe Doorkeeper::TokensController do
|
|
158
156
|
it 'responds with full token introspection' do
|
159
157
|
request.headers['Authorization'] = basic_auth_header_for_client(client)
|
160
158
|
|
161
|
-
post :introspect, token: access_token.token
|
159
|
+
post :introspect, params: { token: access_token.token }
|
162
160
|
|
163
161
|
should_have_json 'active', true
|
164
162
|
expect(json_response).to include('client_id', 'token_type', 'exp', 'iat')
|
@@ -173,7 +171,7 @@ describe Doorkeeper::TokensController do
|
|
173
171
|
it 'responds with full token introspection' do
|
174
172
|
request.headers['Authorization'] = basic_auth_header_for_client(client)
|
175
173
|
|
176
|
-
post :introspect, token: access_token.token
|
174
|
+
post :introspect, params: { token: access_token.token }
|
177
175
|
|
178
176
|
should_have_json 'active', true
|
179
177
|
expect(json_response).to include('client_id', 'token_type', 'exp', 'iat')
|
@@ -189,7 +187,7 @@ describe Doorkeeper::TokensController do
|
|
189
187
|
it 'responds with only active state' do
|
190
188
|
request.headers['Authorization'] = basic_auth_header_for_client(different_client)
|
191
189
|
|
192
|
-
post :introspect, token: access_token.token
|
190
|
+
post :introspect, params: { token: access_token.token }
|
193
191
|
|
194
192
|
expect(response).to be_successful
|
195
193
|
|
@@ -205,7 +203,7 @@ describe Doorkeeper::TokensController do
|
|
205
203
|
it 'responds with invalid_client error' do
|
206
204
|
request.headers['Authorization'] = basic_auth_header_for_client(client)
|
207
205
|
|
208
|
-
post :introspect, token: access_token.token
|
206
|
+
post :introspect, params: { token: access_token.token }
|
209
207
|
|
210
208
|
expect(response).not_to be_successful
|
211
209
|
response_status_should_be 401
|
@@ -222,7 +220,7 @@ describe Doorkeeper::TokensController do
|
|
222
220
|
it 'responds with only active state' do
|
223
221
|
request.headers['Authorization'] = basic_auth_header_for_client(client)
|
224
222
|
|
225
|
-
post :introspect, token: SecureRandom.hex(16)
|
223
|
+
post :introspect, params: { token: SecureRandom.hex(16) }
|
226
224
|
|
227
225
|
should_have_json 'active', false
|
228
226
|
expect(json_response).not_to include('client_id', 'token_type', 'exp', 'iat')
|
@@ -236,7 +234,7 @@ describe Doorkeeper::TokensController do
|
|
236
234
|
it 'responds with only active state' do
|
237
235
|
request.headers['Authorization'] = basic_auth_header_for_client(client)
|
238
236
|
|
239
|
-
post :introspect, token: access_token.token
|
237
|
+
post :introspect, params: { token: access_token.token }
|
240
238
|
|
241
239
|
should_have_json 'active', false
|
242
240
|
expect(json_response).not_to include('client_id', 'token_type', 'exp', 'iat')
|
@@ -250,7 +248,7 @@ describe Doorkeeper::TokensController do
|
|
250
248
|
it 'responds with only active state' do
|
251
249
|
request.headers['Authorization'] = basic_auth_header_for_client(client)
|
252
250
|
|
253
|
-
post :introspect, token: access_token.token
|
251
|
+
post :introspect, params: { token: access_token.token }
|
254
252
|
|
255
253
|
should_have_json 'active', false
|
256
254
|
expect(json_response).not_to include('client_id', 'token_type', 'exp', 'iat')
|
@@ -261,7 +259,7 @@ describe Doorkeeper::TokensController do
|
|
261
259
|
let(:access_token) { FactoryBot.create(:access_token) }
|
262
260
|
|
263
261
|
it 'responds with invalid_request error' do
|
264
|
-
post :introspect, token: access_token.token
|
262
|
+
post :introspect, params: { token: access_token.token }
|
265
263
|
|
266
264
|
expect(response).not_to be_successful
|
267
265
|
response_status_should_be 401
|
@@ -7,6 +7,10 @@ Dummy::Application.configure do
|
|
7
7
|
# and recreated between test runs. Don't rely on the data there!
|
8
8
|
config.cache_classes = true
|
9
9
|
|
10
|
+
config.assets.enabled = true
|
11
|
+
config.assets.version = '1.0'
|
12
|
+
config.assets.digest = false
|
13
|
+
|
10
14
|
# Do not eager load code on boot. This avoids loading your whole application
|
11
15
|
# just for the purpose of running a single test. If you are using a tool that
|
12
16
|
# preloads Rails for running tests, you may have to set it to true.
|
@@ -36,9 +40,4 @@ Dummy::Application.configure do
|
|
36
40
|
config.active_support.deprecation = :stderr
|
37
41
|
|
38
42
|
config.eager_load = true
|
39
|
-
|
40
|
-
if DOORKEEPER_ORM == :active_record
|
41
|
-
config.active_record.table_name_prefix = TABLE_NAME_PREFIX.to_s
|
42
|
-
config.active_record.table_name_suffix = TABLE_NAME_SUFFIX.to_s
|
43
|
-
end
|
44
43
|
end
|
@@ -8,7 +8,11 @@ Doorkeeper.configure do
|
|
8
8
|
User.where(id: session[:user_id]).first || redirect_to(root_url, alert: 'Needs sign in.')
|
9
9
|
end
|
10
10
|
|
11
|
-
# If you
|
11
|
+
# If you didn't skip applications controller from Doorkeeper routes in your application routes.rb
|
12
|
+
# file then you need to declare this block in order to restrict access to the web interface for
|
13
|
+
# adding oauth authorized applications. In other case it will return 403 Forbidden response
|
14
|
+
# every time somebody will try to access the admin web interface.
|
15
|
+
#
|
12
16
|
# admin_authenticator do
|
13
17
|
# # Put your admin authentication logic here.
|
14
18
|
# # Example implementation:
|
@@ -29,10 +33,11 @@ Doorkeeper.configure do
|
|
29
33
|
# Issue access tokens with refresh token (disabled by default)
|
30
34
|
use_refresh_token
|
31
35
|
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
+
# Forbids creating/updating applications with arbitrary scopes that are
|
37
|
+
# not in configuration, i.e. `default_scopes` or `optional_scopes`.
|
38
|
+
# (disabled by default)
|
39
|
+
#
|
40
|
+
# enforce_configured_scopes
|
36
41
|
|
37
42
|
# Provide support for an owner to be assigned to each registered application (disabled by default)
|
38
43
|
# Optional parameter confirmation: true (default false) if you want to enforce ownership of
|
@@ -3,4 +3,8 @@
|
|
3
3
|
# made on earlier versions of Rails are not affected when upgrading.
|
4
4
|
if Rails::VERSION::MAJOR >= 5
|
5
5
|
Rails.application.config.active_record.belongs_to_required_by_default = true
|
6
|
+
|
7
|
+
if Rails::VERSION::MINOR >= 2
|
8
|
+
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
|
9
|
+
end
|
6
10
|
end
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,52 +1,13 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
use_doorkeeper
|
3
|
-
use_doorkeeper scope: 'scope'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
controllers authorizations: 'custom_authorizations',
|
8
|
-
tokens: 'custom_authorizations',
|
9
|
-
applications: 'custom_authorizations',
|
10
|
-
token_info: 'custom_authorizations'
|
11
|
-
|
12
|
-
as authorizations: 'custom_auth',
|
13
|
-
tokens: 'custom_token',
|
14
|
-
token_info: 'custom_token_info'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
scope 'space' do
|
19
|
-
use_doorkeeper do
|
20
|
-
controllers authorizations: 'custom_authorizations',
|
21
|
-
tokens: 'custom_authorizations',
|
22
|
-
applications: 'custom_authorizations',
|
23
|
-
token_info: 'custom_authorizations'
|
24
|
-
|
25
|
-
as authorizations: 'custom_auth',
|
26
|
-
tokens: 'custom_token',
|
27
|
-
token_info: 'custom_token_info'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
scope 'outer_space' do
|
32
|
-
use_doorkeeper do
|
33
|
-
controllers authorizations: 'custom_authorizations',
|
34
|
-
tokens: 'custom_authorizations',
|
35
|
-
token_info: 'custom_authorizations'
|
36
|
-
|
37
|
-
as authorizations: 'custom_auth',
|
38
|
-
tokens: 'custom_token',
|
39
|
-
token_info: 'custom_token_info'
|
40
|
-
|
41
|
-
skip_controllers :tokens, :applications, :token_info
|
42
|
-
end
|
43
|
-
end
|
4
|
+
resources :semi_protected_resources
|
5
|
+
resources :full_protected_resources
|
44
6
|
|
45
7
|
get 'metal.json' => 'metal#index'
|
46
8
|
|
47
9
|
get '/callback', to: 'home#callback'
|
48
10
|
get '/sign_in', to: 'home#sign_in'
|
49
|
-
|
50
|
-
resources :full_protected_resources
|
11
|
+
|
51
12
|
root to: 'home#index'
|
52
13
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
# This file is auto-generated from the current state of the database. Instead
|
3
2
|
# of editing this file, please use the migrations feature of Active Record to
|
4
3
|
# incrementally modify your database, and then regenerate this schema definition.
|
@@ -14,55 +13,56 @@
|
|
14
13
|
ActiveRecord::Schema.define(version: 20180210183654) do
|
15
14
|
|
16
15
|
create_table "oauth_access_grants", force: :cascade do |t|
|
17
|
-
t.integer
|
18
|
-
t.integer
|
19
|
-
t.string
|
20
|
-
t.integer
|
21
|
-
t.text
|
22
|
-
t.datetime "created_at",
|
16
|
+
t.integer "resource_owner_id", null: false
|
17
|
+
t.integer "application_id", null: false
|
18
|
+
t.string "token", null: false
|
19
|
+
t.integer "expires_in", null: false
|
20
|
+
t.text "redirect_uri", null: false
|
21
|
+
t.datetime "created_at", null: false
|
23
22
|
t.datetime "revoked_at"
|
24
|
-
t.string
|
23
|
+
t.string "scopes"
|
24
|
+
unless ENV['WITHOUT_PKCE']
|
25
|
+
t.string "code_challenge"
|
26
|
+
t.string "code_challenge_method"
|
27
|
+
end
|
28
|
+
t.index ["token"], name: "index_oauth_access_grants_on_token", unique: true
|
25
29
|
end
|
26
30
|
|
27
|
-
add_index "oauth_access_grants", ["token"], name: "index_oauth_access_grants_on_token", unique: true
|
28
|
-
|
29
31
|
create_table "oauth_access_tokens", force: :cascade do |t|
|
30
|
-
t.integer
|
31
|
-
t.integer
|
32
|
-
t.string
|
33
|
-
t.string
|
34
|
-
t.integer
|
32
|
+
t.integer "resource_owner_id"
|
33
|
+
t.integer "application_id"
|
34
|
+
t.string "token", null: false
|
35
|
+
t.string "refresh_token"
|
36
|
+
t.integer "expires_in"
|
35
37
|
t.datetime "revoked_at"
|
36
|
-
t.datetime "created_at",
|
37
|
-
t.string
|
38
|
-
t.string
|
38
|
+
t.datetime "created_at", null: false
|
39
|
+
t.string "scopes"
|
40
|
+
t.string "previous_refresh_token", default: "", null: false
|
41
|
+
t.index ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true
|
42
|
+
t.index ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id"
|
43
|
+
t.index ["token"], name: "index_oauth_access_tokens_on_token", unique: true
|
39
44
|
end
|
40
45
|
|
41
|
-
add_index "oauth_access_tokens", ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true
|
42
|
-
add_index "oauth_access_tokens", ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id"
|
43
|
-
add_index "oauth_access_tokens", ["token"], name: "index_oauth_access_tokens_on_token", unique: true
|
44
|
-
|
45
46
|
create_table "oauth_applications", force: :cascade do |t|
|
46
|
-
t.string
|
47
|
-
t.string
|
48
|
-
t.string
|
49
|
-
t.text
|
50
|
-
t.string
|
51
|
-
t.datetime "created_at"
|
52
|
-
t.datetime "updated_at"
|
53
|
-
t.integer
|
54
|
-
t.string
|
47
|
+
t.string "name", null: false
|
48
|
+
t.string "uid", null: false
|
49
|
+
t.string "secret", null: false
|
50
|
+
t.text "redirect_uri", null: false
|
51
|
+
t.string "scopes", default: "", null: false
|
52
|
+
t.datetime "created_at", null: false
|
53
|
+
t.datetime "updated_at", null: false
|
54
|
+
t.integer "owner_id"
|
55
|
+
t.string "owner_type"
|
55
56
|
t.boolean "confidential", default: true, null: false
|
57
|
+
t.index ["owner_id", "owner_type"], name: "index_oauth_applications_on_owner_id_and_owner_type"
|
58
|
+
t.index ["uid"], name: "index_oauth_applications_on_uid", unique: true
|
56
59
|
end
|
57
60
|
|
58
|
-
add_index "oauth_applications", ["owner_id", "owner_type"], name: "index_oauth_applications_on_owner_id_and_owner_type"
|
59
|
-
add_index "oauth_applications", ["uid"], name: "index_oauth_applications_on_uid", unique: true
|
60
|
-
|
61
61
|
create_table "users", force: :cascade do |t|
|
62
|
-
t.string
|
62
|
+
t.string "name"
|
63
63
|
t.datetime "created_at"
|
64
64
|
t.datetime "updated_at"
|
65
|
-
t.string
|
65
|
+
t.string "password"
|
66
66
|
end
|
67
67
|
|
68
68
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'generators/doorkeeper/confidential_applications_generator'
|
5
|
+
|
6
|
+
describe 'Doorkeeper::ConfidentialApplicationsGenerator' do
|
7
|
+
include GeneratorSpec::TestCase
|
8
|
+
|
9
|
+
tests Doorkeeper::ConfidentialApplicationsGenerator
|
10
|
+
destination ::File.expand_path('../tmp/dummy', __FILE__)
|
11
|
+
|
12
|
+
describe 'after running the generator' do
|
13
|
+
before :each do
|
14
|
+
prepare_destination
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'pre Rails 5.0.0' do
|
18
|
+
it 'creates a migration with no version specifier' do
|
19
|
+
stub_const("ActiveRecord::VERSION::MAJOR", 4)
|
20
|
+
stub_const("ActiveRecord::VERSION::MINOR", 2)
|
21
|
+
|
22
|
+
run_generator
|
23
|
+
|
24
|
+
assert_migration 'db/migrate/add_confidential_to_applications.rb' do |migration|
|
25
|
+
assert migration.include?("ActiveRecord::Migration\n")
|
26
|
+
assert migration.include?(':confidential')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'post Rails 5.0.0' do
|
32
|
+
it 'creates a migration with a version specifier' do
|
33
|
+
stub_const("ActiveRecord::VERSION::MAJOR", 5)
|
34
|
+
stub_const("ActiveRecord::VERSION::MINOR", 0)
|
35
|
+
|
36
|
+
run_generator
|
37
|
+
|
38
|
+
assert_migration 'db/migrate/add_confidential_to_applications.rb' do |migration|
|
39
|
+
assert migration.include?("ActiveRecord::Migration[5.0]\n")
|
40
|
+
assert migration.include?(':confidential')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'generators/doorkeeper/pkce_generator'
|
5
|
+
|
6
|
+
describe 'Doorkeeper::PkceGenerator' do
|
7
|
+
include GeneratorSpec::TestCase
|
8
|
+
|
9
|
+
tests Doorkeeper::PkceGenerator
|
10
|
+
destination ::File.expand_path('../tmp/dummy', __FILE__)
|
11
|
+
|
12
|
+
describe 'after running the generator' do
|
13
|
+
before :each do
|
14
|
+
prepare_destination
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'pre Rails 5.0.0' do
|
18
|
+
it 'creates a migration with no version specifier' do
|
19
|
+
stub_const("ActiveRecord::VERSION::MAJOR", 4)
|
20
|
+
stub_const("ActiveRecord::VERSION::MINOR", 2)
|
21
|
+
|
22
|
+
run_generator
|
23
|
+
|
24
|
+
assert_migration 'db/migrate/enable_pkce.rb' do |migration|
|
25
|
+
assert migration.include?("ActiveRecord::Migration\n")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'post Rails 5.0.0' do
|
31
|
+
it 'creates a migration with a version specifier' do
|
32
|
+
stub_const("ActiveRecord::VERSION::MAJOR", 5)
|
33
|
+
stub_const("ActiveRecord::VERSION::MINOR", 0)
|
34
|
+
|
35
|
+
run_generator
|
36
|
+
|
37
|
+
assert_migration 'db/migrate/enable_pkce.rb' do |migration|
|
38
|
+
assert migration.include?("ActiveRecord::Migration[5.0]\n")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|