doorkeeper 4.4.3 → 5.0.3

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.

Files changed (223) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.gitlab-ci.yml +16 -0
  4. data/.travis.yml +7 -0
  5. data/Appraisals +2 -2
  6. data/Dangerfile +64 -0
  7. data/Gemfile +1 -1
  8. data/NEWS.md +98 -8
  9. data/README.md +110 -12
  10. data/Rakefile +6 -0
  11. data/UPGRADE.md +2 -0
  12. data/app/assets/stylesheets/doorkeeper/admin/application.css +2 -2
  13. data/app/controllers/doorkeeper/application_controller.rb +6 -3
  14. data/app/controllers/doorkeeper/application_metal_controller.rb +6 -0
  15. data/app/controllers/doorkeeper/applications_controller.rb +46 -24
  16. data/app/controllers/doorkeeper/authorizations_controller.rb +55 -12
  17. data/app/controllers/doorkeeper/authorized_applications_controller.rb +21 -2
  18. data/app/controllers/doorkeeper/token_info_controller.rb +2 -0
  19. data/app/controllers/doorkeeper/tokens_controller.rb +4 -6
  20. data/app/helpers/doorkeeper/dashboard_helper.rb +9 -7
  21. data/app/validators/redirect_uri_validator.rb +5 -2
  22. data/app/views/doorkeeper/applications/_delete_form.html.erb +3 -1
  23. data/app/views/doorkeeper/applications/_form.html.erb +25 -24
  24. data/app/views/doorkeeper/applications/edit.html.erb +1 -1
  25. data/app/views/doorkeeper/applications/index.html.erb +17 -7
  26. data/app/views/doorkeeper/applications/new.html.erb +1 -1
  27. data/app/views/doorkeeper/applications/show.html.erb +6 -6
  28. data/app/views/doorkeeper/authorizations/error.html.erb +1 -1
  29. data/app/views/doorkeeper/authorizations/new.html.erb +4 -0
  30. data/app/views/layouts/doorkeeper/admin.html.erb +15 -15
  31. data/config/locales/en.yml +10 -1
  32. data/doorkeeper.gemspec +25 -26
  33. data/gemfiles/rails_5_2.gemfile +1 -1
  34. data/gemfiles/rails_master.gemfile +4 -1
  35. data/lib/doorkeeper/config.rb +81 -40
  36. data/lib/doorkeeper/engine.rb +6 -0
  37. data/lib/doorkeeper/errors.rb +17 -3
  38. data/lib/doorkeeper/grape/authorization_decorator.rb +2 -0
  39. data/lib/doorkeeper/grape/helpers.rb +3 -1
  40. data/lib/doorkeeper/helpers/controller.rb +9 -2
  41. data/lib/doorkeeper/models/access_grant_mixin.rb +73 -0
  42. data/lib/doorkeeper/models/access_token_mixin.rb +44 -25
  43. data/lib/doorkeeper/models/application_mixin.rb +2 -0
  44. data/lib/doorkeeper/models/concerns/accessible.rb +2 -0
  45. data/lib/doorkeeper/models/concerns/expirable.rb +2 -0
  46. data/lib/doorkeeper/models/concerns/orderable.rb +2 -0
  47. data/lib/doorkeeper/models/concerns/ownership.rb +2 -0
  48. data/lib/doorkeeper/models/concerns/revocable.rb +2 -0
  49. data/lib/doorkeeper/models/concerns/scopes.rb +3 -1
  50. data/lib/doorkeeper/oauth/authorization/code.rb +33 -8
  51. data/lib/doorkeeper/oauth/authorization/context.rb +17 -0
  52. data/lib/doorkeeper/oauth/authorization/token.rb +38 -14
  53. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +2 -0
  54. data/lib/doorkeeper/oauth/authorization_code_request.rb +29 -2
  55. data/lib/doorkeeper/oauth/base_request.rb +22 -9
  56. data/lib/doorkeeper/oauth/base_response.rb +2 -0
  57. data/lib/doorkeeper/oauth/client/credentials.rb +3 -1
  58. data/lib/doorkeeper/oauth/client.rb +1 -1
  59. data/lib/doorkeeper/oauth/client_credentials/creator.rb +4 -1
  60. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +7 -2
  61. data/lib/doorkeeper/oauth/client_credentials/validation.rb +5 -5
  62. data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -3
  63. data/lib/doorkeeper/oauth/code_request.rb +2 -0
  64. data/lib/doorkeeper/oauth/code_response.rb +2 -0
  65. data/lib/doorkeeper/oauth/error.rb +2 -0
  66. data/lib/doorkeeper/oauth/error_response.rb +21 -3
  67. data/lib/doorkeeper/oauth/forbidden_token_response.rb +9 -2
  68. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +2 -8
  69. data/lib/doorkeeper/oauth/helpers/unique_token.rb +2 -0
  70. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +5 -2
  71. data/lib/doorkeeper/oauth/invalid_token_response.rb +18 -0
  72. data/lib/doorkeeper/oauth/password_access_token_request.rb +9 -4
  73. data/lib/doorkeeper/oauth/pre_authorization.rb +43 -11
  74. data/lib/doorkeeper/oauth/refresh_token_request.rb +16 -3
  75. data/lib/doorkeeper/oauth/scopes.rb +3 -1
  76. data/lib/doorkeeper/oauth/token.rb +7 -2
  77. data/lib/doorkeeper/oauth/token_introspection.rb +4 -2
  78. data/lib/doorkeeper/oauth/token_request.rb +2 -0
  79. data/lib/doorkeeper/oauth/token_response.rb +6 -2
  80. data/lib/doorkeeper/oauth.rb +13 -0
  81. data/lib/doorkeeper/orm/active_record/application.rb +75 -12
  82. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +26 -0
  83. data/lib/doorkeeper/orm/active_record.rb +4 -0
  84. data/lib/doorkeeper/rails/helpers.rb +6 -4
  85. data/lib/doorkeeper/rails/routes/mapper.rb +2 -0
  86. data/lib/doorkeeper/rails/routes/mapping.rb +2 -0
  87. data/lib/doorkeeper/rails/routes.rb +23 -8
  88. data/lib/doorkeeper/rake/db.rake +40 -0
  89. data/lib/doorkeeper/rake/setup.rake +6 -0
  90. data/lib/doorkeeper/rake.rb +14 -0
  91. data/lib/doorkeeper/request/authorization_code.rb +1 -1
  92. data/lib/doorkeeper/request/client_credentials.rb +1 -1
  93. data/lib/doorkeeper/request/code.rb +1 -1
  94. data/lib/doorkeeper/request/password.rb +1 -1
  95. data/lib/doorkeeper/request/refresh_token.rb +1 -1
  96. data/lib/doorkeeper/request/strategy.rb +2 -0
  97. data/lib/doorkeeper/request/token.rb +1 -1
  98. data/lib/doorkeeper/request.rb +29 -34
  99. data/lib/doorkeeper/server.rb +2 -0
  100. data/lib/doorkeeper/stale_records_cleaner.rb +20 -0
  101. data/lib/doorkeeper/validations.rb +2 -0
  102. data/lib/doorkeeper/version.rb +6 -24
  103. data/lib/doorkeeper.rb +20 -17
  104. data/lib/generators/doorkeeper/application_owner_generator.rb +23 -18
  105. data/lib/generators/doorkeeper/confidential_applications_generator.rb +32 -0
  106. data/lib/generators/doorkeeper/install_generator.rb +17 -9
  107. data/lib/generators/doorkeeper/migration_generator.rb +23 -18
  108. data/lib/generators/doorkeeper/pkce_generator.rb +32 -0
  109. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +29 -24
  110. data/lib/generators/doorkeeper/templates/add_confidential_to_applications.rb.erb +13 -0
  111. data/lib/generators/doorkeeper/templates/enable_pkce_migration.rb.erb +6 -0
  112. data/lib/generators/doorkeeper/templates/initializer.rb +96 -13
  113. data/lib/generators/doorkeeper/templates/migration.rb.erb +2 -3
  114. data/lib/generators/doorkeeper/views_generator.rb +3 -1
  115. data/spec/controllers/application_metal_controller_spec.rb +50 -0
  116. data/spec/controllers/applications_controller_spec.rb +123 -14
  117. data/spec/controllers/authorizations_controller_spec.rb +334 -51
  118. data/spec/controllers/protected_resources_controller_spec.rb +60 -18
  119. data/spec/controllers/token_info_controller_spec.rb +4 -12
  120. data/spec/controllers/tokens_controller_spec.rb +17 -20
  121. data/spec/dummy/Rakefile +1 -1
  122. data/spec/dummy/app/assets/config/manifest.js +2 -0
  123. data/spec/dummy/app/controllers/custom_authorizations_controller.rb +1 -1
  124. data/spec/dummy/app/controllers/home_controller.rb +1 -2
  125. data/spec/dummy/config/application.rb +1 -1
  126. data/spec/dummy/config/boot.rb +2 -4
  127. data/spec/dummy/config/environment.rb +1 -1
  128. data/spec/dummy/config/environments/test.rb +5 -6
  129. data/spec/dummy/config/initializers/doorkeeper.rb +12 -6
  130. data/spec/dummy/config/initializers/new_framework_defaults.rb +2 -0
  131. data/spec/dummy/config/initializers/secret_token.rb +1 -1
  132. data/spec/dummy/config/routes.rb +3 -42
  133. data/spec/dummy/config.ru +1 -1
  134. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +4 -4
  135. data/spec/dummy/db/migrate/20151223200000_add_owner_to_application.rb +1 -1
  136. data/spec/dummy/db/migrate/20170822064514_enable_pkce.rb +6 -0
  137. data/spec/dummy/db/migrate/{20180210183654_add_confidential_to_application.rb → 20180210183654_add_confidential_to_applications.rb} +1 -1
  138. data/spec/dummy/db/schema.rb +36 -36
  139. data/spec/dummy/script/rails +4 -3
  140. data/spec/factories.rb +6 -6
  141. data/spec/generators/application_owner_generator_spec.rb +1 -1
  142. data/spec/generators/confidential_applications_generator_spec.rb +45 -0
  143. data/spec/generators/install_generator_spec.rb +5 -2
  144. data/spec/generators/migration_generator_spec.rb +1 -1
  145. data/spec/generators/pkce_generator_spec.rb +43 -0
  146. data/spec/generators/previous_refresh_token_generator_spec.rb +1 -1
  147. data/spec/generators/templates/routes.rb +0 -1
  148. data/spec/generators/views_generator_spec.rb +2 -2
  149. data/spec/grape/grape_integration_spec.rb +2 -2
  150. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  151. data/spec/lib/config_spec.rb +105 -39
  152. data/spec/lib/doorkeeper_spec.rb +6 -131
  153. data/spec/lib/models/expirable_spec.rb +0 -3
  154. data/spec/lib/models/revocable_spec.rb +0 -2
  155. data/spec/lib/models/scopes_spec.rb +0 -4
  156. data/spec/lib/oauth/authorization/uri_builder_spec.rb +0 -4
  157. data/spec/lib/oauth/authorization_code_request_spec.rb +17 -7
  158. data/spec/lib/oauth/base_request_spec.rb +49 -11
  159. data/spec/lib/oauth/base_response_spec.rb +1 -1
  160. data/spec/lib/oauth/client/credentials_spec.rb +2 -4
  161. data/spec/lib/oauth/client_credentials/creator_spec.rb +5 -1
  162. data/spec/lib/oauth/client_credentials/issuer_spec.rb +24 -7
  163. data/spec/lib/oauth/client_credentials/validation_spec.rb +4 -4
  164. data/spec/lib/oauth/client_credentials_integration_spec.rb +2 -2
  165. data/spec/lib/oauth/client_credentials_request_spec.rb +3 -5
  166. data/spec/lib/oauth/client_spec.rb +0 -3
  167. data/spec/lib/oauth/code_request_spec.rb +5 -3
  168. data/spec/lib/oauth/code_response_spec.rb +1 -1
  169. data/spec/lib/oauth/error_response_spec.rb +0 -3
  170. data/spec/lib/oauth/error_spec.rb +0 -2
  171. data/spec/lib/oauth/forbidden_token_response_spec.rb +1 -4
  172. data/spec/lib/oauth/helpers/scope_checker_spec.rb +8 -11
  173. data/spec/lib/oauth/helpers/unique_token_spec.rb +0 -1
  174. data/spec/lib/oauth/helpers/uri_checker_spec.rb +22 -13
  175. data/spec/lib/oauth/invalid_token_response_spec.rb +1 -4
  176. data/spec/lib/oauth/password_access_token_request_spec.rb +53 -6
  177. data/spec/lib/oauth/pre_authorization_spec.rb +33 -4
  178. data/spec/lib/oauth/refresh_token_request_spec.rb +22 -14
  179. data/spec/lib/oauth/scopes_spec.rb +0 -3
  180. data/spec/lib/oauth/token_request_spec.rb +8 -9
  181. data/spec/lib/oauth/token_response_spec.rb +0 -1
  182. data/spec/lib/oauth/token_spec.rb +40 -14
  183. data/spec/lib/request/strategy_spec.rb +0 -1
  184. data/spec/lib/server_spec.rb +7 -7
  185. data/spec/lib/stale_records_cleaner_spec.rb +89 -0
  186. data/spec/models/doorkeeper/access_grant_spec.rb +44 -1
  187. data/spec/models/doorkeeper/access_token_spec.rb +80 -32
  188. data/spec/models/doorkeeper/application_spec.rb +293 -221
  189. data/spec/requests/applications/applications_request_spec.rb +134 -1
  190. data/spec/requests/applications/authorized_applications_spec.rb +1 -1
  191. data/spec/requests/endpoints/authorization_spec.rb +3 -3
  192. data/spec/requests/endpoints/token_spec.rb +7 -5
  193. data/spec/requests/flows/authorization_code_errors_spec.rb +2 -2
  194. data/spec/requests/flows/authorization_code_spec.rb +258 -2
  195. data/spec/requests/flows/client_credentials_spec.rb +46 -6
  196. data/spec/requests/flows/implicit_grant_errors_spec.rb +3 -3
  197. data/spec/requests/flows/implicit_grant_spec.rb +38 -11
  198. data/spec/requests/flows/password_spec.rb +61 -3
  199. data/spec/requests/flows/refresh_token_spec.rb +59 -2
  200. data/spec/requests/flows/revoke_token_spec.rb +20 -20
  201. data/spec/requests/flows/skip_authorization_spec.rb +16 -11
  202. data/spec/requests/protected_resources/metal_spec.rb +1 -1
  203. data/spec/requests/protected_resources/private_api_spec.rb +3 -3
  204. data/spec/routing/custom_controller_routes_spec.rb +59 -7
  205. data/spec/routing/default_routes_spec.rb +2 -2
  206. data/spec/routing/scoped_routes_spec.rb +16 -2
  207. data/spec/spec_helper.rb +54 -3
  208. data/spec/spec_helper_integration.rb +2 -74
  209. data/spec/support/dependencies/{factory_girl.rb → factory_bot.rb} +0 -0
  210. data/spec/support/doorkeeper_rspec.rb +20 -0
  211. data/spec/support/helpers/authorization_request_helper.rb +4 -4
  212. data/spec/support/helpers/model_helper.rb +8 -4
  213. data/spec/support/helpers/request_spec_helper.rb +10 -2
  214. data/spec/support/helpers/url_helper.rb +18 -14
  215. data/spec/support/http_method_shim.rb +12 -16
  216. data/spec/support/shared/controllers_shared_context.rb +56 -0
  217. data/spec/validators/redirect_uri_validator_spec.rb +9 -3
  218. data/spec/version/version_spec.rb +3 -3
  219. data/vendor/assets/stylesheets/doorkeeper/bootstrap.min.css +4 -5
  220. metadata +54 -35
  221. data/lib/generators/doorkeeper/add_client_confidentiality_generator.rb +0 -31
  222. data/lib/generators/doorkeeper/templates/add_confidential_to_application_migration.rb.erb +0 -11
  223. data/spec/controllers/application_metal_controller.rb +0 -10
@@ -1,32 +1,24 @@
1
- require 'spec_helper_integration'
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 tokeninfo' do
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,13 +1,9 @@
1
- require 'spec_helper_integration'
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
-
11
7
  it 'returns the authorization' do
12
8
  skip 'verify need of these specs'
13
9
 
@@ -33,12 +29,12 @@ describe Doorkeeper::TokensController do
33
29
  it 'returns the error response with a custom message' do
34
30
  # I18n looks for `doorkeeper.errors.messages.custom_message` in locale files
35
31
  custom_message = "my_message"
36
- allow(I18n).to receive(:translate).
37
- with(
32
+ allow(I18n).to receive(:translate)
33
+ .with(
38
34
  custom_message,
39
- hash_including(scope: %i[doorkeeper errors messages]),
40
- ).
41
- and_return('Authorization custom message')
35
+ hash_including(scope: %i[doorkeeper errors messages])
36
+ )
37
+ .and_return('Authorization custom message')
42
38
 
43
39
  doorkeeper_error = Doorkeeper::Errors::DoorkeeperError.new(custom_message)
44
40
 
@@ -129,7 +125,8 @@ describe Doorkeeper::TokensController do
129
125
  expect(strategy).to receive(:authorize).once
130
126
  allow(controller).to receive(:strategy) { strategy }
131
127
  allow(controller).to receive(:create) do
132
- controller.send :authorize_response
128
+ 2.times { controller.send :authorize_response }
129
+ controller.render json: {}, status: :ok
133
130
  end
134
131
 
135
132
  post :create
@@ -144,7 +141,7 @@ describe Doorkeeper::TokensController do
144
141
  it 'responds with full token introspection' do
145
142
  request.headers['Authorization'] = "Bearer #{access_token.token}"
146
143
 
147
- post :introspect, token: access_token.token
144
+ post :introspect, params: { token: access_token.token }
148
145
 
149
146
  should_have_json 'active', true
150
147
  expect(json_response).to include('client_id', 'token_type', 'exp', 'iat')
@@ -158,7 +155,7 @@ describe Doorkeeper::TokensController do
158
155
  it 'responds with full token introspection' do
159
156
  request.headers['Authorization'] = basic_auth_header_for_client(client)
160
157
 
161
- post :introspect, token: access_token.token
158
+ post :introspect, params: { token: access_token.token }
162
159
 
163
160
  should_have_json 'active', true
164
161
  expect(json_response).to include('client_id', 'token_type', 'exp', 'iat')
@@ -173,7 +170,7 @@ describe Doorkeeper::TokensController do
173
170
  it 'responds with full token introspection' do
174
171
  request.headers['Authorization'] = basic_auth_header_for_client(client)
175
172
 
176
- post :introspect, token: access_token.token
173
+ post :introspect, params: { token: access_token.token }
177
174
 
178
175
  should_have_json 'active', true
179
176
  expect(json_response).to include('client_id', 'token_type', 'exp', 'iat')
@@ -189,7 +186,7 @@ describe Doorkeeper::TokensController do
189
186
  it 'responds with only active state' do
190
187
  request.headers['Authorization'] = basic_auth_header_for_client(different_client)
191
188
 
192
- post :introspect, token: access_token.token
189
+ post :introspect, params: { token: access_token.token }
193
190
 
194
191
  expect(response).to be_successful
195
192
 
@@ -205,7 +202,7 @@ describe Doorkeeper::TokensController do
205
202
  it 'responds with invalid_client error' do
206
203
  request.headers['Authorization'] = basic_auth_header_for_client(client)
207
204
 
208
- post :introspect, token: access_token.token
205
+ post :introspect, params: { token: access_token.token }
209
206
 
210
207
  expect(response).not_to be_successful
211
208
  response_status_should_be 401
@@ -222,7 +219,7 @@ describe Doorkeeper::TokensController do
222
219
  it 'responds with only active state' do
223
220
  request.headers['Authorization'] = basic_auth_header_for_client(client)
224
221
 
225
- post :introspect, token: SecureRandom.hex(16)
222
+ post :introspect, params: { token: SecureRandom.hex(16) }
226
223
 
227
224
  should_have_json 'active', false
228
225
  expect(json_response).not_to include('client_id', 'token_type', 'exp', 'iat')
@@ -236,7 +233,7 @@ describe Doorkeeper::TokensController do
236
233
  it 'responds with only active state' do
237
234
  request.headers['Authorization'] = basic_auth_header_for_client(client)
238
235
 
239
- post :introspect, token: access_token.token
236
+ post :introspect, params: { token: access_token.token }
240
237
 
241
238
  should_have_json 'active', false
242
239
  expect(json_response).not_to include('client_id', 'token_type', 'exp', 'iat')
@@ -250,7 +247,7 @@ describe Doorkeeper::TokensController do
250
247
  it 'responds with only active state' do
251
248
  request.headers['Authorization'] = basic_auth_header_for_client(client)
252
249
 
253
- post :introspect, token: access_token.token
250
+ post :introspect, params: { token: access_token.token }
254
251
 
255
252
  should_have_json 'active', false
256
253
  expect(json_response).not_to include('client_id', 'token_type', 'exp', 'iat')
@@ -261,7 +258,7 @@ describe Doorkeeper::TokensController do
261
258
  let(:access_token) { FactoryBot.create(:access_token) }
262
259
 
263
260
  it 'responds with invalid_request error' do
264
- post :introspect, token: access_token.token
261
+ post :introspect, params: { token: access_token.token }
265
262
 
266
263
  expect(response).not_to be_successful
267
264
  response_status_should_be 401
data/spec/dummy/Rakefile CHANGED
@@ -2,6 +2,6 @@
2
2
  # Add your own tasks in files placed in lib/tasks ending in .rake,
3
3
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
4
 
5
- require File.expand_path('../config/application', __FILE__)
5
+ require File.expand_path('config/application', __dir__)
6
6
 
7
7
  Dummy::Application.load_tasks
@@ -0,0 +1,2 @@
1
+ // JS and CSS bundles
2
+ //
@@ -1,5 +1,5 @@
1
1
  class CustomAuthorizationsController < ::ApplicationController
2
- %w(index show new create edit update destroy).each do |action|
2
+ %w[index show new create edit update destroy].each do |action|
3
3
  define_method action do
4
4
  render nothing: true
5
5
  end
@@ -1,6 +1,5 @@
1
1
  class HomeController < ApplicationController
2
- def index
3
- end
2
+ def index; end
4
3
 
5
4
  def sign_in
6
5
  session[:user_id] = if Rails.env.development?
@@ -1,4 +1,4 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require File.expand_path('boot', __dir__)
2
2
 
3
3
  require 'rails/all'
4
4
 
@@ -2,8 +2,6 @@ require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
4
  orm = ENV['BUNDLE_GEMFILE'].match(/Gemfile\.(.+)\.rb/)
5
- unless defined?(DOORKEEPER_ORM)
6
- DOORKEEPER_ORM = (orm && orm[1]) || :active_record
7
- end
5
+ DOORKEEPER_ORM = (orm && orm[1]) || :active_record unless defined?(DOORKEEPER_ORM)
8
6
 
9
- $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
7
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
@@ -1,5 +1,5 @@
1
1
  # Load the rails application
2
- require File.expand_path('../application', __FILE__)
2
+ require File.expand_path('application', __dir__)
3
3
 
4
4
  # Initialize the rails application
5
5
  Rails.application.initialize!
@@ -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.
@@ -20,7 +24,7 @@ Dummy::Application.configure do
20
24
  config.action_dispatch.show_exceptions = false
21
25
 
22
26
  # Disable request forgery protection in test environment
23
- config.action_controller.allow_forgery_protection = false
27
+ config.action_controller.allow_forgery_protection = false
24
28
 
25
29
  # Tell Action Mailer not to deliver emails to the real world.
26
30
  # The :test delivery method accumulates sent emails in the
@@ -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 want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.
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
- # Opt out of breaking api change to the native authorization code flow. Opting out sets the authorization
33
- # code response route for native redirect uris to oauth/authorize/<code>. The default is oauth/authorize/native?code=<code>.
34
- # Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/1143
35
- # opt_out_native_route_change
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
@@ -59,7 +64,8 @@ Doorkeeper.configure do
59
64
  # access_token_methods :from_bearer_authorization, :from_access_token_param, :from_bearer_param
60
65
 
61
66
  # Change the native redirect uri for client apps
62
- # When clients register with the following redirect uri, they won't be redirected to any server and the authorization code will be displayed within the provider
67
+ # When clients register with the following redirect uri, they won't be redirected to any server and
68
+ # the authorization code will be displayed within the provider
63
69
  # The value can be any string. Use nil to disable this feature. When disabled, clients must provide a valid URL
64
70
  # (Similar behaviour: https://developers.google.com/accounts/docs/OAuth2InstalledApp#choosingredirecturi)
65
71
  #
@@ -3,4 +3,6 @@
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
+ Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true if Rails::VERSION::MINOR >= 2
6
8
  end
@@ -5,4 +5,4 @@
5
5
  # Make sure the secret is at least 30 characters and all random,
6
6
  # no regular words or you'll be exposed to dictionary attacks.
7
7
  Dummy::Application.config.secret_key_base =
8
- 'c00157b5a1bb6181792f0f4a8a080485de7bab9987e6cf159dc74c4f0573345c1bfa713b5d756e1491fc0b098567e8a619e2f8d268eda86a20a720d05d633780'
8
+ 'c00157b5a1bb6181792f0f4a8a080485de7bab9987e6cf159'
@@ -1,52 +1,13 @@
1
1
  Rails.application.routes.draw do
2
2
  use_doorkeeper
3
- use_doorkeeper scope: 'scope'
4
3
 
5
- scope 'inner_space' do
6
- use_doorkeeper scope: 'scope' do
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
- resources :semi_protected_resources
50
- resources :full_protected_resources
11
+
51
12
  root to: 'home#index'
52
13
  end
data/spec/dummy/config.ru CHANGED
@@ -1,4 +1,4 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
4
  run Dummy::Application
@@ -28,7 +28,7 @@ class CreateDoorkeeperTables < ActiveRecord::Migration[4.2]
28
28
  add_foreign_key(
29
29
  :oauth_access_grants,
30
30
  :oauth_applications,
31
- column: :application_id,
31
+ column: :application_id
32
32
  )
33
33
 
34
34
  create_table :oauth_access_tokens do |t|
@@ -41,12 +41,12 @@ class CreateDoorkeeperTables < ActiveRecord::Migration[4.2]
41
41
  # https://github.com/doorkeeper-gem/doorkeeper/tree/v3.0.0.rc1#custom-access-token-generator
42
42
  #
43
43
  # t.text :token, null: false
44
- t.string :token, null: false
44
+ t.string :token, null: false
45
45
 
46
46
  t.string :refresh_token
47
47
  t.integer :expires_in
48
48
  t.datetime :revoked_at
49
- t.datetime :created_at, null: false
49
+ t.datetime :created_at, null: false
50
50
  t.string :scopes
51
51
  end
52
52
 
@@ -56,7 +56,7 @@ class CreateDoorkeeperTables < ActiveRecord::Migration[4.2]
56
56
  add_foreign_key(
57
57
  :oauth_access_tokens,
58
58
  :oauth_applications,
59
- column: :application_id,
59
+ column: :application_id
60
60
  )
61
61
  end
62
62
  end
@@ -4,6 +4,6 @@ class AddOwnerToApplication < ActiveRecord::Migration[4.2]
4
4
  def change
5
5
  add_column :oauth_applications, :owner_id, :integer, null: true
6
6
  add_column :oauth_applications, :owner_type, :string, null: true
7
- add_index :oauth_applications, [:owner_id, :owner_type]
7
+ add_index :oauth_applications, %i[owner_id owner_type]
8
8
  end
9
9
  end
@@ -0,0 +1,6 @@
1
+ class EnablePkce < ActiveRecord::Migration[4.2]
2
+ def change
3
+ add_column :oauth_access_grants, :code_challenge, :string, null: true
4
+ add_column :oauth_access_grants, :code_challenge_method, :string, null: true
5
+ end
6
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class AddConfidentialToApplication < ActiveRecord::Migration[5.1]
3
+ class AddConfidentialToApplications < ActiveRecord::Migration[5.1]
4
4
  def change
5
5
  add_column(
6
6
  :oauth_applications,
@@ -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 "resource_owner_id", null: false
18
- t.integer "application_id", null: false
19
- t.string "token", null: false
20
- t.integer "expires_in", null: false
21
- t.text "redirect_uri", null: false
22
- t.datetime "created_at", null: false
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 "scopes"
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 "resource_owner_id"
31
- t.integer "application_id"
32
- t.string "token", null: false
33
- t.string "refresh_token"
34
- t.integer "expires_in"
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", null: false
37
- t.string "scopes"
38
- t.string "previous_refresh_token", default: "", null: false
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 "name", null: false
47
- t.string "uid", null: false
48
- t.string "secret", null: false
49
- t.text "redirect_uri", null: false
50
- t.string "scopes", default: "", null: false
51
- t.datetime "created_at"
52
- t.datetime "updated_at"
53
- t.integer "owner_id"
54
- t.string "owner_type"
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 "name"
62
+ t.string "name"
63
63
  t.datetime "created_at"
64
64
  t.datetime "updated_at"
65
- t.string "password"
65
+ t.string "password"
66
66
  end
67
67
 
68
68
  end
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems
3
+ # installed from the root of your application.
3
4
 
4
- APP_PATH = File.expand_path('../../config/application', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
5
+ APP_PATH = File.expand_path('../config/application', __dir__)
6
+ require File.expand_path('../config/boot', __dir__)
6
7
  require 'rails/commands'
data/spec/factories.rb CHANGED
@@ -2,24 +2,24 @@ FactoryBot.define do
2
2
  factory :access_grant, class: Doorkeeper::AccessGrant do
3
3
  sequence(:resource_owner_id) { |n| n }
4
4
  application
5
- redirect_uri 'https://app.com/callback'
6
- expires_in 100
7
- scopes 'public write'
5
+ redirect_uri { 'https://app.com/callback' }
6
+ expires_in { 100 }
7
+ scopes { 'public write' }
8
8
  end
9
9
 
10
10
  factory :access_token, class: Doorkeeper::AccessToken do
11
11
  sequence(:resource_owner_id) { |n| n }
12
12
  application
13
- expires_in 2.hours
13
+ expires_in { 2.hours }
14
14
 
15
15
  factory :clientless_access_token do
16
- application nil
16
+ application { nil }
17
17
  end
18
18
  end
19
19
 
20
20
  factory :application, class: Doorkeeper::Application do
21
21
  sequence(:name) { |n| "Application #{n}" }
22
- redirect_uri 'https://app.com/callback'
22
+ redirect_uri { 'https://app.com/callback' }
23
23
  end
24
24
 
25
25
  # do not name this factory :user, otherwise it will conflict with factories
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
  require 'generators/doorkeeper/application_owner_generator'
3
3
 
4
4
  describe 'Doorkeeper::ApplicationOwnerGenerator' do
@@ -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
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
  require 'generators/doorkeeper/install_generator'
3
3
 
4
4
  describe 'Doorkeeper::InstallGenerator' do
@@ -12,7 +12,10 @@ describe 'Doorkeeper::InstallGenerator' do
12
12
  prepare_destination
13
13
  FileUtils.mkdir(::File.expand_path('config', Pathname(destination_root)))
14
14
  FileUtils.mkdir(::File.expand_path('db', Pathname(destination_root)))
15
- FileUtils.copy_file(::File.expand_path('../templates/routes.rb', __FILE__), ::File.expand_path('config/routes.rb', Pathname.new(destination_root)))
15
+ FileUtils.copy_file(
16
+ ::File.expand_path('../templates/routes.rb', __FILE__),
17
+ ::File.expand_path('config/routes.rb', Pathname.new(destination_root))
18
+ )
16
19
  run_generator
17
20
  end
18
21
 
@@ -1,4 +1,4 @@
1
- require 'spec_helper_integration'
1
+ require 'spec_helper'
2
2
  require 'generators/doorkeeper/migration_generator'
3
3
 
4
4
  describe 'Doorkeeper::MigrationGenerator' do