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,46 +1,41 @@
1
- require 'doorkeeper/request/authorization_code'
2
- require 'doorkeeper/request/client_credentials'
3
- require 'doorkeeper/request/code'
4
- require 'doorkeeper/request/password'
5
- require 'doorkeeper/request/refresh_token'
6
- require 'doorkeeper/request/token'
1
+ # frozen_string_literal: true
7
2
 
8
3
  module Doorkeeper
9
4
  module Request
10
- module_function
5
+ class << self
6
+ def authorization_strategy(response_type)
7
+ get_strategy(response_type, authorization_response_types)
8
+ rescue NameError
9
+ raise Errors::InvalidAuthorizationStrategy
10
+ end
11
11
 
12
- def authorization_strategy(response_type)
13
- get_strategy response_type, authorization_response_types
14
- rescue NameError
15
- raise Errors::InvalidAuthorizationStrategy
16
- end
12
+ def token_strategy(grant_type)
13
+ get_strategy(grant_type, token_grant_types)
14
+ rescue NameError
15
+ raise Errors::InvalidTokenStrategy
16
+ end
17
17
 
18
- def token_strategy(grant_type)
19
- get_strategy grant_type, token_grant_types
20
- rescue NameError
21
- raise Errors::InvalidTokenStrategy
22
- end
18
+ def get_strategy(grant_or_request_type, available)
19
+ raise Errors::MissingRequestStrategy if grant_or_request_type.blank?
20
+ raise NameError unless available.include?(grant_or_request_type.to_s)
23
21
 
24
- def get_strategy(grant_or_request_type, available)
25
- fail Errors::MissingRequestStrategy unless grant_or_request_type.present?
26
- fail NameError unless available.include?(grant_or_request_type.to_s)
27
- strategy_class(grant_or_request_type)
28
- end
22
+ build_strategy_class(grant_or_request_type)
23
+ end
29
24
 
30
- def authorization_response_types
31
- Doorkeeper.configuration.authorization_response_types
32
- end
33
- private_class_method :authorization_response_types
25
+ private
34
26
 
35
- def token_grant_types
36
- Doorkeeper.configuration.token_grant_types
37
- end
38
- private_class_method :token_grant_types
27
+ def authorization_response_types
28
+ Doorkeeper.configuration.authorization_response_types
29
+ end
30
+
31
+ def token_grant_types
32
+ Doorkeeper.configuration.token_grant_types
33
+ end
39
34
 
40
- def strategy_class(grant_or_request_type)
41
- strategy_class_name = grant_or_request_type.to_s.tr(' ', '_').camelize
42
- "Doorkeeper::Request::#{strategy_class_name}".constantize
35
+ def build_strategy_class(grant_or_request_type)
36
+ strategy_class_name = grant_or_request_type.to_s.tr(' ', '_').camelize
37
+ "Doorkeeper::Request::#{strategy_class_name}".constantize
38
+ end
43
39
  end
44
- private_class_method :strategy_class
45
40
  end
46
41
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  class Server
3
5
  attr_accessor :context
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doorkeeper
4
+ class StaleRecordsCleaner
5
+ CLEANER_CLASS = 'StaleRecordsCleaner'.freeze
6
+
7
+ def self.for(base_scope)
8
+ orm_adapter = "doorkeeper/orm/#{Doorkeeper.configuration.orm}".classify
9
+
10
+ orm_cleaner = "#{orm_adapter}::#{CLEANER_CLASS}".constantize
11
+ orm_cleaner.new(base_scope)
12
+ rescue NameError
13
+ raise Doorkeeper::Errors::NoOrmCleaner, "'#{Doorkeeper.configuration.orm}' ORM has no cleaner!"
14
+ end
15
+
16
+ def self.new(base_scope)
17
+ self.for(base_scope)
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Doorkeeper
2
4
  module Validations
3
5
  extend ActiveSupport::Concern
@@ -1,36 +1,18 @@
1
- module Doorkeeper
2
- CVE_2018_1000211_WARNING = <<-HEREDOC.freeze
3
-
4
-
5
- WARNING: This is a security release that addresses token revocation not working for public apps (CVE-2018-1000211)
6
-
7
- There is no breaking change in this release, however to take advantage of the security fix you must:
8
-
9
- 1. Run `rails generate doorkeeper:add_client_confidentiality` for the migration
10
- 2. Review your OAuth apps and determine which ones exclusively use public grant flows (eg implicit)
11
- 3. Update their `confidential` column to `false` for those public apps
12
-
13
- This is a backported security release.
14
-
15
- For more information:
16
-
17
- * https://github.com/doorkeeper-gem/doorkeeper/pull/1119
18
- * https://github.com/doorkeeper-gem/doorkeeper/issues/891
19
-
20
-
21
- HEREDOC
1
+ # frozen_string_literal: true
22
2
 
3
+ module Doorkeeper
23
4
  def self.gem_version
24
5
  Gem::Version.new VERSION::STRING
25
6
  end
26
7
 
27
8
  module VERSION
28
9
  # Semantic versioning
29
- MAJOR = 4
30
- MINOR = 4
10
+ MAJOR = 5
11
+ MINOR = 0
31
12
  TINY = 3
13
+ PRE = nil
32
14
 
33
15
  # Full version number
34
- STRING = [MAJOR, MINOR, TINY].compact.join('.')
16
+ STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
35
17
  end
36
18
  end
data/lib/doorkeeper.rb CHANGED
@@ -2,18 +2,28 @@ require 'doorkeeper/version'
2
2
  require 'doorkeeper/engine'
3
3
  require 'doorkeeper/config'
4
4
 
5
+ require 'doorkeeper/request/strategy'
6
+ require 'doorkeeper/request/authorization_code'
7
+ require 'doorkeeper/request/client_credentials'
8
+ require 'doorkeeper/request/code'
9
+ require 'doorkeeper/request/password'
10
+ require 'doorkeeper/request/refresh_token'
11
+ require 'doorkeeper/request/token'
12
+
5
13
  require 'doorkeeper/errors'
6
14
  require 'doorkeeper/server'
7
15
  require 'doorkeeper/request'
8
16
  require 'doorkeeper/validations'
9
17
 
10
18
  require 'doorkeeper/oauth/authorization/code'
19
+ require 'doorkeeper/oauth/authorization/context'
11
20
  require 'doorkeeper/oauth/authorization/token'
12
21
  require 'doorkeeper/oauth/authorization/uri_builder'
13
22
  require 'doorkeeper/oauth/helpers/scope_checker'
14
23
  require 'doorkeeper/oauth/helpers/uri_checker'
15
24
  require 'doorkeeper/oauth/helpers/unique_token'
16
25
 
26
+ require 'doorkeeper/oauth'
17
27
  require 'doorkeeper/oauth/scopes'
18
28
  require 'doorkeeper/oauth/error'
19
29
  require 'doorkeeper/oauth/base_response'
@@ -25,6 +35,13 @@ require 'doorkeeper/oauth/base_request'
25
35
  require 'doorkeeper/oauth/authorization_code_request'
26
36
  require 'doorkeeper/oauth/refresh_token_request'
27
37
  require 'doorkeeper/oauth/password_access_token_request'
38
+
39
+ require 'doorkeeper/oauth/client_credentials/validation'
40
+ require 'doorkeeper/oauth/client_credentials/creator'
41
+ require 'doorkeeper/oauth/client_credentials/issuer'
42
+ require 'doorkeeper/oauth/client_credentials/validation'
43
+ require 'doorkeeper/oauth/client/credentials'
44
+
28
45
  require 'doorkeeper/oauth/client_credentials_request'
29
46
  require 'doorkeeper/oauth/code_request'
30
47
  require 'doorkeeper/oauth/token_request'
@@ -49,26 +66,12 @@ require 'doorkeeper/helpers/controller'
49
66
  require 'doorkeeper/rails/routes'
50
67
  require 'doorkeeper/rails/helpers'
51
68
 
52
- require 'doorkeeper/orm/active_record'
69
+ require 'doorkeeper/rake'
70
+ require 'doorkeeper/stale_records_cleaner'
53
71
 
54
- require 'active_support/deprecation'
72
+ require 'doorkeeper/orm/active_record'
55
73
 
56
74
  module Doorkeeper
57
- def self.configured?
58
- ActiveSupport::Deprecation.warn "Method `Doorkeeper#configured?` has been deprecated without replacement."
59
- @config.present?
60
- end
61
-
62
- def self.database_installed?
63
- ActiveSupport::Deprecation.warn "Method `Doorkeeper#database_installed?` has been deprecated without replacement."
64
- [AccessToken, AccessGrant, Application].all?(&:table_exists?)
65
- end
66
-
67
- def self.installed?
68
- ActiveSupport::Deprecation.warn "Method `Doorkeeper#installed?` has been deprecated without replacement."
69
- configured? && database_installed?
70
- end
71
-
72
75
  def self.authenticate(request, methods = Doorkeeper.configuration.access_token_methods)
73
76
  OAuth::Token.authenticate(request, *methods)
74
77
  end
@@ -1,27 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
1
4
  require 'rails/generators/active_record'
2
5
 
3
- class Doorkeeper::ApplicationOwnerGenerator < Rails::Generators::Base
4
- include Rails::Generators::Migration
5
- source_root File.expand_path('../templates', __FILE__)
6
- desc 'Provide support for client application ownership.'
6
+ module Doorkeeper
7
+ class ApplicationOwnerGenerator < ::Rails::Generators::Base
8
+ include ::Rails::Generators::Migration
9
+ source_root File.expand_path('templates', __dir__)
10
+ desc 'Provide support for client application ownership.'
7
11
 
8
- def application_owner
9
- migration_template(
10
- 'add_owner_to_application_migration.rb.erb',
11
- 'db/migrate/add_owner_to_application.rb',
12
- migration_version: migration_version
13
- )
14
- end
12
+ def application_owner
13
+ migration_template(
14
+ 'add_owner_to_application_migration.rb.erb',
15
+ 'db/migrate/add_owner_to_application.rb',
16
+ migration_version: migration_version
17
+ )
18
+ end
15
19
 
16
- def self.next_migration_number(dirname)
17
- ActiveRecord::Generators::Base.next_migration_number(dirname)
18
- end
20
+ def self.next_migration_number(dirname)
21
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
22
+ end
19
23
 
20
- private
24
+ private
21
25
 
22
- def migration_version
23
- if ActiveRecord::VERSION::MAJOR >= 5
24
- "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
26
+ def migration_version
27
+ if ActiveRecord::VERSION::MAJOR >= 5
28
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
29
+ end
25
30
  end
26
31
  end
27
32
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+ require 'rails/generators/active_record'
5
+
6
+ module Doorkeeper
7
+ class ConfidentialApplicationsGenerator < ::Rails::Generators::Base
8
+ include ::Rails::Generators::Migration
9
+ source_root File.expand_path('templates', __dir__)
10
+ desc 'Add confidential column to Doorkeeper applications'
11
+
12
+ def pkce
13
+ migration_template(
14
+ 'add_confidential_to_applications.rb.erb',
15
+ 'db/migrate/add_confidential_to_applications.rb',
16
+ migration_version: migration_version
17
+ )
18
+ end
19
+
20
+ def self.next_migration_number(dirname)
21
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
22
+ end
23
+
24
+ private
25
+
26
+ def migration_version
27
+ if ActiveRecord::VERSION::MAJOR >= 5
28
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,12 +1,20 @@
1
- class Doorkeeper::InstallGenerator < ::Rails::Generators::Base
2
- include Rails::Generators::Migration
3
- source_root File.expand_path('../templates', __FILE__)
4
- desc 'Installs Doorkeeper.'
1
+ # frozen_string_literal: true
5
2
 
6
- def install
7
- template 'initializer.rb', 'config/initializers/doorkeeper.rb'
8
- copy_file File.expand_path('../../../../config/locales/en.yml', __FILE__), 'config/locales/doorkeeper.en.yml'
9
- route 'use_doorkeeper'
10
- readme 'README'
3
+ require 'rails/generators'
4
+ require 'rails/generators/active_record'
5
+
6
+ module Doorkeeper
7
+ class InstallGenerator < ::Rails::Generators::Base
8
+ include ::Rails::Generators::Migration
9
+ source_root File.expand_path('templates', __dir__)
10
+ desc 'Installs Doorkeeper.'
11
+
12
+ def install
13
+ template 'initializer.rb', 'config/initializers/doorkeeper.rb'
14
+ copy_file File.expand_path('../../../config/locales/en.yml', __dir__),
15
+ 'config/locales/doorkeeper.en.yml'
16
+ route 'use_doorkeeper'
17
+ readme 'README'
18
+ end
11
19
  end
12
20
  end
@@ -1,27 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
1
4
  require 'rails/generators/active_record'
2
5
 
3
- class Doorkeeper::MigrationGenerator < ::Rails::Generators::Base
4
- include Rails::Generators::Migration
5
- source_root File.expand_path('../templates', __FILE__)
6
- desc 'Installs Doorkeeper migration file.'
6
+ module Doorkeeper
7
+ class MigrationGenerator < ::Rails::Generators::Base
8
+ include ::Rails::Generators::Migration
9
+ source_root File.expand_path('templates', __dir__)
10
+ desc 'Installs Doorkeeper migration file.'
7
11
 
8
- def install
9
- migration_template(
10
- 'migration.rb.erb',
11
- 'db/migrate/create_doorkeeper_tables.rb',
12
- migration_version: migration_version
13
- )
14
- end
12
+ def install
13
+ migration_template(
14
+ 'migration.rb.erb',
15
+ 'db/migrate/create_doorkeeper_tables.rb',
16
+ migration_version: migration_version
17
+ )
18
+ end
15
19
 
16
- def self.next_migration_number(dirname)
17
- ActiveRecord::Generators::Base.next_migration_number(dirname)
18
- end
20
+ def self.next_migration_number(dirname)
21
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
22
+ end
19
23
 
20
- private
24
+ private
21
25
 
22
- def migration_version
23
- if ActiveRecord::VERSION::MAJOR >= 5
24
- "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
26
+ def migration_version
27
+ if ActiveRecord::VERSION::MAJOR >= 5
28
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
29
+ end
25
30
  end
26
31
  end
27
32
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+ require 'rails/generators/active_record'
5
+
6
+ module Doorkeeper
7
+ class PkceGenerator < ::Rails::Generators::Base
8
+ include ::Rails::Generators::Migration
9
+ source_root File.expand_path('templates', __dir__)
10
+ desc 'Provide support for PKCE.'
11
+
12
+ def pkce
13
+ migration_template(
14
+ 'enable_pkce_migration.rb.erb',
15
+ 'db/migrate/enable_pkce.rb',
16
+ migration_version: migration_version
17
+ )
18
+ end
19
+
20
+ def self.next_migration_number(dirname)
21
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
22
+ end
23
+
24
+ private
25
+
26
+ def migration_version
27
+ if ActiveRecord::VERSION::MAJOR >= 5
28
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,35 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
1
4
  require 'rails/generators/active_record'
2
5
 
3
- class Doorkeeper::PreviousRefreshTokenGenerator < Rails::Generators::Base
4
- include Rails::Generators::Migration
5
- source_root File.expand_path('../templates', __FILE__)
6
- desc 'Support revoke refresh token on access token use'
6
+ module Doorkeeper
7
+ class PreviousRefreshTokenGenerator < ::Rails::Generators::Base
8
+ include ::Rails::Generators::Migration
9
+ source_root File.expand_path('templates', __dir__)
10
+ desc 'Support revoke refresh token on access token use'
7
11
 
8
- def self.next_migration_number(path)
9
- ActiveRecord::Generators::Base.next_migration_number(path)
10
- end
12
+ def self.next_migration_number(path)
13
+ ActiveRecord::Generators::Base.next_migration_number(path)
14
+ end
11
15
 
12
- def previous_refresh_token
13
- if no_previous_refresh_token_column?
14
- migration_template(
15
- 'add_previous_refresh_token_to_access_tokens.rb.erb',
16
- 'db/migrate/add_previous_refresh_token_to_access_tokens.rb'
17
- )
16
+ def previous_refresh_token
17
+ if no_previous_refresh_token_column?
18
+ migration_template(
19
+ 'add_previous_refresh_token_to_access_tokens.rb.erb',
20
+ 'db/migrate/add_previous_refresh_token_to_access_tokens.rb'
21
+ )
22
+ end
18
23
  end
19
- end
20
24
 
21
- private
25
+ private
22
26
 
23
- def migration_version
24
- if ActiveRecord::VERSION::MAJOR >= 5
25
- "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
27
+ def migration_version
28
+ if ActiveRecord::VERSION::MAJOR >= 5
29
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
30
+ end
26
31
  end
27
- end
28
32
 
29
- def no_previous_refresh_token_column?
30
- !ActiveRecord::Base.connection.column_exists?(
31
- :oauth_access_tokens,
32
- :previous_refresh_token
33
- )
33
+ def no_previous_refresh_token_column?
34
+ !ActiveRecord::Base.connection.column_exists?(
35
+ :oauth_access_tokens,
36
+ :previous_refresh_token
37
+ )
38
+ end
34
39
  end
35
40
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddConfidentialToApplications < ActiveRecord::Migration<%= migration_version %>
4
+ def change
5
+ add_column(
6
+ :oauth_applications,
7
+ :confidential,
8
+ :boolean,
9
+ null: false,
10
+ default: true
11
+ )
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ class EnablePkce < ActiveRecord::Migration<%= migration_version %>
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