doorkeeper 4.3.2 → 5.0.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/.gitignore +1 -0
- data/.gitlab-ci.yml +16 -0
- data/.rubocop.yml +4 -0
- data/.travis.yml +2 -0
- data/Appraisals +2 -2
- data/Gemfile +1 -1
- data/NEWS.md +70 -0
- 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 +43 -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 +11 -16
- 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 +31 -19
- data/app/views/doorkeeper/applications/edit.html.erb +1 -1
- data/app/views/doorkeeper/applications/index.html.erb +18 -6
- data/app/views/doorkeeper/applications/new.html.erb +1 -1
- data/app/views/doorkeeper/applications/show.html.erb +8 -5
- 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 +16 -1
- data/doorkeeper.gemspec +18 -18
- data/gemfiles/rails_5_2.gemfile +1 -1
- data/gemfiles/rails_master.gemfile +4 -1
- data/lib/doorkeeper/config.rb +77 -27
- 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 +40 -23
- data/lib/doorkeeper/models/application_mixin.rb +8 -1
- 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 +4 -2
- 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/helpers/uri_checker.rb +1 -0
- data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -4
- data/lib/doorkeeper/oauth/pre_authorization.rb +45 -13
- 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 +25 -0
- 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 +13 -1
- 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 +1 -13
- 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 -4
- 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/templates/migration.rb.erb +1 -0
- 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 +279 -17
- 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 +72 -22
- 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 +11 -1
- data/spec/dummy/config/initializers/new_framework_defaults.rb +4 -0
- data/spec/dummy/config/routes.rb +3 -42
- data/spec/dummy/db/migrate/20111122132257_create_users.rb +3 -1
- data/spec/dummy/db/migrate/20120312140401_add_password_to_users.rb +3 -1
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +3 -1
- data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +3 -1
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +3 -1
- data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +13 -0
- data/spec/dummy/db/schema.rb +38 -37
- 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 +88 -14
- 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 +24 -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 +5 -5
- 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 -2
- 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 +40 -6
- 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 +64 -6
- 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 +198 -2
- 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 +120 -23
- 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/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 +36 -10
- data/spec/controllers/application_metal_controller.rb +0 -10
- /data/spec/support/dependencies/{factory_girl.rb → factory_bot.rb} +0 -0
|
@@ -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
|
|
|
@@ -59,15 +56,67 @@ describe Doorkeeper::TokensController do
|
|
|
59
56
|
end
|
|
60
57
|
end
|
|
61
58
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
# http://tools.ietf.org/html/rfc7009#section-2.2
|
|
60
|
+
describe 'revoking tokens' do
|
|
61
|
+
let(:client) { FactoryBot.create(:application) }
|
|
62
|
+
let(:access_token) { FactoryBot.create(:access_token, application: client) }
|
|
63
|
+
|
|
64
|
+
before(:each) do
|
|
65
|
+
allow(controller).to receive(:token) { access_token }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
context 'when associated app is public' do
|
|
69
|
+
let(:client) { FactoryBot.create(:application, confidential: false) }
|
|
70
|
+
|
|
71
|
+
it 'returns 200' do
|
|
72
|
+
post :revoke
|
|
73
|
+
|
|
74
|
+
expect(response.status).to eq 200
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'revokes the access token' do
|
|
78
|
+
post :revoke
|
|
79
|
+
|
|
80
|
+
expect(access_token.reload).to have_attributes(revoked?: true)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
67
83
|
|
|
68
|
-
|
|
84
|
+
context 'when associated app is confidential' do
|
|
85
|
+
let(:client) { FactoryBot.create(:application, confidential: true) }
|
|
86
|
+
let(:oauth_client) { Doorkeeper::OAuth::Client.new(client) }
|
|
69
87
|
|
|
70
|
-
|
|
88
|
+
before(:each) do
|
|
89
|
+
allow_any_instance_of(Doorkeeper::Server).to receive(:client) { oauth_client }
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it 'returns 200' do
|
|
93
|
+
post :revoke
|
|
94
|
+
|
|
95
|
+
expect(response.status).to eq 200
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'revokes the access token' do
|
|
99
|
+
post :revoke
|
|
100
|
+
|
|
101
|
+
expect(access_token.reload).to have_attributes(revoked?: true)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
context 'when authorization fails' do
|
|
105
|
+
let(:some_other_client) { FactoryBot.create(:application, confidential: true) }
|
|
106
|
+
let(:oauth_client) { Doorkeeper::OAuth::Client.new(some_other_client) }
|
|
107
|
+
|
|
108
|
+
it 'returns 200' do
|
|
109
|
+
post :revoke
|
|
110
|
+
|
|
111
|
+
expect(response.status).to eq 200
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
it 'does not revoke the access token' do
|
|
115
|
+
post :revoke
|
|
116
|
+
|
|
117
|
+
expect(access_token.reload).to have_attributes(revoked?: false)
|
|
118
|
+
end
|
|
119
|
+
end
|
|
71
120
|
end
|
|
72
121
|
end
|
|
73
122
|
|
|
@@ -77,7 +126,8 @@ describe Doorkeeper::TokensController do
|
|
|
77
126
|
expect(strategy).to receive(:authorize).once
|
|
78
127
|
allow(controller).to receive(:strategy) { strategy }
|
|
79
128
|
allow(controller).to receive(:create) do
|
|
80
|
-
controller.send :authorize_response
|
|
129
|
+
2.times { controller.send :authorize_response }
|
|
130
|
+
controller.render json: {}, status: :ok
|
|
81
131
|
end
|
|
82
132
|
|
|
83
133
|
post :create
|
|
@@ -92,7 +142,7 @@ describe Doorkeeper::TokensController do
|
|
|
92
142
|
it 'responds with full token introspection' do
|
|
93
143
|
request.headers['Authorization'] = "Bearer #{access_token.token}"
|
|
94
144
|
|
|
95
|
-
post :introspect, token: access_token.token
|
|
145
|
+
post :introspect, params: { token: access_token.token }
|
|
96
146
|
|
|
97
147
|
should_have_json 'active', true
|
|
98
148
|
expect(json_response).to include('client_id', 'token_type', 'exp', 'iat')
|
|
@@ -106,7 +156,7 @@ describe Doorkeeper::TokensController do
|
|
|
106
156
|
it 'responds with full token introspection' do
|
|
107
157
|
request.headers['Authorization'] = basic_auth_header_for_client(client)
|
|
108
158
|
|
|
109
|
-
post :introspect, token: access_token.token
|
|
159
|
+
post :introspect, params: { token: access_token.token }
|
|
110
160
|
|
|
111
161
|
should_have_json 'active', true
|
|
112
162
|
expect(json_response).to include('client_id', 'token_type', 'exp', 'iat')
|
|
@@ -121,7 +171,7 @@ describe Doorkeeper::TokensController do
|
|
|
121
171
|
it 'responds with full token introspection' do
|
|
122
172
|
request.headers['Authorization'] = basic_auth_header_for_client(client)
|
|
123
173
|
|
|
124
|
-
post :introspect, token: access_token.token
|
|
174
|
+
post :introspect, params: { token: access_token.token }
|
|
125
175
|
|
|
126
176
|
should_have_json 'active', true
|
|
127
177
|
expect(json_response).to include('client_id', 'token_type', 'exp', 'iat')
|
|
@@ -137,7 +187,7 @@ describe Doorkeeper::TokensController do
|
|
|
137
187
|
it 'responds with only active state' do
|
|
138
188
|
request.headers['Authorization'] = basic_auth_header_for_client(different_client)
|
|
139
189
|
|
|
140
|
-
post :introspect, token: access_token.token
|
|
190
|
+
post :introspect, params: { token: access_token.token }
|
|
141
191
|
|
|
142
192
|
expect(response).to be_successful
|
|
143
193
|
|
|
@@ -153,7 +203,7 @@ describe Doorkeeper::TokensController do
|
|
|
153
203
|
it 'responds with invalid_client error' do
|
|
154
204
|
request.headers['Authorization'] = basic_auth_header_for_client(client)
|
|
155
205
|
|
|
156
|
-
post :introspect, token: access_token.token
|
|
206
|
+
post :introspect, params: { token: access_token.token }
|
|
157
207
|
|
|
158
208
|
expect(response).not_to be_successful
|
|
159
209
|
response_status_should_be 401
|
|
@@ -170,7 +220,7 @@ describe Doorkeeper::TokensController do
|
|
|
170
220
|
it 'responds with only active state' do
|
|
171
221
|
request.headers['Authorization'] = basic_auth_header_for_client(client)
|
|
172
222
|
|
|
173
|
-
post :introspect, token: SecureRandom.hex(16)
|
|
223
|
+
post :introspect, params: { token: SecureRandom.hex(16) }
|
|
174
224
|
|
|
175
225
|
should_have_json 'active', false
|
|
176
226
|
expect(json_response).not_to include('client_id', 'token_type', 'exp', 'iat')
|
|
@@ -184,7 +234,7 @@ describe Doorkeeper::TokensController do
|
|
|
184
234
|
it 'responds with only active state' do
|
|
185
235
|
request.headers['Authorization'] = basic_auth_header_for_client(client)
|
|
186
236
|
|
|
187
|
-
post :introspect, token: access_token.token
|
|
237
|
+
post :introspect, params: { token: access_token.token }
|
|
188
238
|
|
|
189
239
|
should_have_json 'active', false
|
|
190
240
|
expect(json_response).not_to include('client_id', 'token_type', 'exp', 'iat')
|
|
@@ -198,7 +248,7 @@ describe Doorkeeper::TokensController do
|
|
|
198
248
|
it 'responds with only active state' do
|
|
199
249
|
request.headers['Authorization'] = basic_auth_header_for_client(client)
|
|
200
250
|
|
|
201
|
-
post :introspect, token: access_token.token
|
|
251
|
+
post :introspect, params: { token: access_token.token }
|
|
202
252
|
|
|
203
253
|
should_have_json 'active', false
|
|
204
254
|
expect(json_response).not_to include('client_id', 'token_type', 'exp', 'iat')
|
|
@@ -209,7 +259,7 @@ describe Doorkeeper::TokensController do
|
|
|
209
259
|
let(:access_token) { FactoryBot.create(:access_token) }
|
|
210
260
|
|
|
211
261
|
it 'responds with invalid_request error' do
|
|
212
|
-
post :introspect, token: access_token.token
|
|
262
|
+
post :introspect, params: { token: access_token.token }
|
|
213
263
|
|
|
214
264
|
expect(response).not_to be_successful
|
|
215
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,6 +33,12 @@ Doorkeeper.configure do
|
|
|
29
33
|
# Issue access tokens with refresh token (disabled by default)
|
|
30
34
|
use_refresh_token
|
|
31
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
|
|
41
|
+
|
|
32
42
|
# Provide support for an owner to be assigned to each registered application (disabled by default)
|
|
33
43
|
# Optional parameter confirmation: true (default false) if you want to enforce ownership of
|
|
34
44
|
# a registered application
|
|
@@ -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
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class AddOwnerToApplication < ActiveRecord::Migration[4.2]
|
|
2
4
|
def change
|
|
3
5
|
add_column :oauth_applications, :owner_id, :integer, null: true
|
|
4
6
|
add_column :oauth_applications, :owner_type, :string, null: true
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class AddConfidentialToApplications < ActiveRecord::Migration[5.1]
|
|
4
|
+
def change
|
|
5
|
+
add_column(
|
|
6
|
+
:oauth_applications,
|
|
7
|
+
:confidential,
|
|
8
|
+
:boolean,
|
|
9
|
+
null: false,
|
|
10
|
+
default: true # maintaining backwards compatibility: require secrets
|
|
11
|
+
)
|
|
12
|
+
end
|
|
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.
|
|
@@ -11,57 +10,59 @@
|
|
|
11
10
|
#
|
|
12
11
|
# It's strongly recommended that you check this file into your version control system.
|
|
13
12
|
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
|
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"
|
|
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
|
|
55
59
|
end
|
|
56
60
|
|
|
57
|
-
add_index "oauth_applications", ["owner_id", "owner_type"], name: "index_oauth_applications_on_owner_id_and_owner_type"
|
|
58
|
-
add_index "oauth_applications", ["uid"], name: "index_oauth_applications_on_uid", unique: true
|
|
59
|
-
|
|
60
61
|
create_table "users", force: :cascade do |t|
|
|
61
|
-
t.string
|
|
62
|
+
t.string "name"
|
|
62
63
|
t.datetime "created_at"
|
|
63
64
|
t.datetime "updated_at"
|
|
64
|
-
t.string
|
|
65
|
+
t.string "password"
|
|
65
66
|
end
|
|
66
67
|
|
|
67
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
|