doorkeeper 5.4.0 → 5.5.0.rc2

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 (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +49 -9
  3. data/app/controllers/doorkeeper/authorizations_controller.rb +16 -5
  4. data/app/controllers/doorkeeper/tokens_controller.rb +34 -26
  5. data/app/views/doorkeeper/applications/show.html.erb +16 -12
  6. data/app/views/doorkeeper/authorizations/form_post.html.erb +11 -0
  7. data/config/locales/en.yml +3 -1
  8. data/lib/doorkeeper/config/option.rb +1 -3
  9. data/lib/doorkeeper/config/validations.rb +53 -0
  10. data/lib/doorkeeper/config.rb +87 -62
  11. data/lib/doorkeeper/grant_flow/fallback_flow.rb +15 -0
  12. data/lib/doorkeeper/grant_flow/flow.rb +44 -0
  13. data/lib/doorkeeper/grant_flow/registry.rb +50 -0
  14. data/lib/doorkeeper/grant_flow.rb +45 -0
  15. data/lib/doorkeeper/helpers/controller.rb +4 -0
  16. data/lib/doorkeeper/models/access_grant_mixin.rb +1 -2
  17. data/lib/doorkeeper/models/access_token_mixin.rb +3 -3
  18. data/lib/doorkeeper/models/concerns/revocable.rb +1 -1
  19. data/lib/doorkeeper/oauth/authorization/code.rb +4 -0
  20. data/lib/doorkeeper/oauth/authorization/context.rb +5 -5
  21. data/lib/doorkeeper/oauth/authorization/token.rb +10 -4
  22. data/lib/doorkeeper/oauth/authorization/uri_builder.rb +1 -1
  23. data/lib/doorkeeper/oauth/authorization_code_request.rb +10 -17
  24. data/lib/doorkeeper/oauth/base_request.rb +1 -1
  25. data/lib/doorkeeper/oauth/client_credentials/creator.rb +2 -1
  26. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +1 -0
  27. data/lib/doorkeeper/oauth/code_response.rb +17 -11
  28. data/lib/doorkeeper/oauth/error_response.rb +4 -3
  29. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +1 -3
  30. data/lib/doorkeeper/oauth/password_access_token_request.rb +20 -1
  31. data/lib/doorkeeper/oauth/pre_authorization.rb +33 -8
  32. data/lib/doorkeeper/oauth/refresh_token_request.rb +13 -0
  33. data/lib/doorkeeper/orm/active_record/mixins/application.rb +6 -3
  34. data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +5 -0
  35. data/lib/doorkeeper/orm/active_record.rb +4 -5
  36. data/lib/doorkeeper/rails/routes.rb +1 -3
  37. data/lib/doorkeeper/request.rb +49 -12
  38. data/lib/doorkeeper/version.rb +2 -6
  39. data/lib/doorkeeper.rb +5 -0
  40. data/lib/generators/doorkeeper/templates/add_owner_to_application_migration.rb.erb +1 -1
  41. data/lib/generators/doorkeeper/templates/initializer.rb +9 -7
  42. metadata +21 -8
@@ -4,32 +4,69 @@ module Doorkeeper
4
4
  module Request
5
5
  class << self
6
6
  def authorization_strategy(response_type)
7
- build_strategy_class(response_type)
7
+ grant_flow = authorization_flows.detect do |flow|
8
+ flow.matches_response_type?(response_type)
9
+ end
10
+
11
+ if grant_flow
12
+ grant_flow.response_type_strategy
13
+ else
14
+ # [NOTE]: this will be removed in a newer versions of Doorkeeper.
15
+ # For retro-compatibility only
16
+ build_fallback_strategy_class(response_type)
17
+ end
8
18
  end
9
19
 
10
20
  def token_strategy(grant_type)
11
21
  raise Errors::MissingRequiredParameter, :grant_type if grant_type.blank?
12
22
 
13
- get_strategy(grant_type, token_grant_types)
14
- rescue NameError
15
- raise Errors::InvalidTokenStrategy
16
- end
23
+ grant_flow = token_flows.detect do |flow|
24
+ flow.matches_grant_type?(grant_type)
25
+ end
17
26
 
18
- def get_strategy(grant_type, available)
19
- raise NameError unless available.include?(grant_type.to_s)
27
+ if grant_flow
28
+ grant_flow.grant_type_strategy
29
+ else
30
+ # [NOTE]: this will be removed in a newer versions of Doorkeeper.
31
+ # For retro-compatibility only
32
+ raise Errors::InvalidTokenStrategy unless available.include?(grant_type.to_s)
20
33
 
21
- build_strategy_class(grant_type)
34
+ strategy_class = build_fallback_strategy_class(grant_type)
35
+ raise Errors::InvalidTokenStrategy unless strategy_class
36
+
37
+ strategy_class
38
+ end
22
39
  end
23
40
 
24
41
  private
25
42
 
26
- def token_grant_types
27
- Doorkeeper.config.token_grant_types
43
+ def authorization_flows
44
+ Doorkeeper.configuration.authorization_response_flows
45
+ end
46
+
47
+ def token_flows
48
+ Doorkeeper.configuration.token_grant_flows
28
49
  end
29
50
 
30
- def build_strategy_class(grant_or_request_type)
51
+ # [NOTE]: this will be removed in a newer versions of Doorkeeper.
52
+ # For retro-compatibility only
53
+ def available
54
+ Doorkeeper.config.deprecated_token_grant_types_resolver
55
+ end
56
+
57
+ def build_fallback_strategy_class(grant_or_request_type)
31
58
  strategy_class_name = grant_or_request_type.to_s.tr(" ", "_").camelize
32
- "Doorkeeper::Request::#{strategy_class_name}".constantize
59
+ fallback_strategy = "Doorkeeper::Request::#{strategy_class_name}".constantize
60
+
61
+ ::Kernel.warn <<~WARNING
62
+ [DOORKEEPER] #{fallback_strategy} found using fallback, it must be
63
+ registered using `Doorkeeper::GrantFlow.register(grant_flow_name, **options)`.
64
+ This functionality will be removed in a newer versions of Doorkeeper.
65
+ WARNING
66
+
67
+ fallback_strategy
68
+ rescue NameError
69
+ raise Errors::InvalidTokenStrategy
33
70
  end
34
71
  end
35
72
  end
@@ -1,16 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Doorkeeper
4
- def self.gem_version
5
- Gem::Version.new VERSION::STRING
6
- end
7
-
8
4
  module VERSION
9
5
  # Semantic versioning
10
6
  MAJOR = 5
11
- MINOR = 4
7
+ MINOR = 5
12
8
  TINY = 0
13
- PRE = nil
9
+ PRE = "rc2"
14
10
 
15
11
  # Full version number
16
12
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
data/lib/doorkeeper.rb CHANGED
@@ -7,6 +7,7 @@ require "doorkeeper/engine"
7
7
  #
8
8
  module Doorkeeper
9
9
  autoload :Errors, "doorkeeper/errors"
10
+ autoload :GrantFlow, "doorkeeper/grant_flow"
10
11
  autoload :OAuth, "doorkeeper/oauth"
11
12
  autoload :Rake, "doorkeeper/rake"
12
13
  autoload :Request, "doorkeeper/request"
@@ -114,4 +115,8 @@ module Doorkeeper
114
115
  def self.authenticate(request, methods = Doorkeeper.config.access_token_methods)
115
116
  OAuth::Token.authenticate(request, *methods)
116
117
  end
118
+
119
+ def self.gem_version
120
+ ::Gem::Version.new(::Doorkeeper::VERSION::STRING)
121
+ end
117
122
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  class AddOwnerToApplication < ActiveRecord::Migration<%= migration_version %>
4
4
  def change
5
- add_column :oauth_applications, :owner_id, :integer, null: true
5
+ add_column :oauth_applications, :owner_id, :bigint, null: true
6
6
  add_column :oauth_applications, :owner_type, :string, null: true
7
7
  add_index :oauth_applications, [:owner_id, :owner_type]
8
8
  end
@@ -103,12 +103,13 @@ Doorkeeper.configure do
103
103
  #
104
104
  # `context` has the following properties available:
105
105
  #
106
- # `client` - the OAuth client application (see Doorkeeper::OAuth::Client)
107
- # `grant_type` - the grant type of the request (see Doorkeeper::OAuth)
108
- # `scopes` - the requested scopes (see Doorkeeper::OAuth::Scopes)
106
+ # * `client` - the OAuth client application (see Doorkeeper::OAuth::Client)
107
+ # * `grant_type` - the grant type of the request (see Doorkeeper::OAuth)
108
+ # * `scopes` - the requested scopes (see Doorkeeper::OAuth::Scopes)
109
+ # * `resource_owner` - authorized resource owner instance (if present)
109
110
  #
110
111
  # custom_access_token_expires_in do |context|
111
- # context.client.application.additional_settings.implicit_oauth_expiration
112
+ # context.client.additional_settings.implicit_oauth_expiration
112
113
  # end
113
114
 
114
115
  # Use a custom class for generating the access token.
@@ -167,8 +168,7 @@ Doorkeeper.configure do
167
168
  # since plain values can no longer be retrieved.
168
169
  #
169
170
  # Note: If you are already a user of doorkeeper and have existing tokens
170
- # in your installation, they will be invalid without enabling the additional
171
- # setting `fallback_to_plain_secrets` below.
171
+ # in your installation, they will be invalid without adding 'fallback: :plain'.
172
172
  #
173
173
  # hash_token_secrets
174
174
  # By default, token secrets will be hashed using the
@@ -202,7 +202,9 @@ Doorkeeper.configure do
202
202
  # This will ensure that old access tokens and secrets
203
203
  # will remain valid even if the hashing above is enabled.
204
204
  #
205
- # fallback_to_plain_secrets
205
+ # This can be done by adding 'fallback: plain', e.g. :
206
+ #
207
+ # hash_application_secrets using: '::Doorkeeper::SecretStoring::BCrypt', fallback: :plain
206
208
 
207
209
  # Issue access tokens with refresh token (disabled by default), you may also
208
210
  # pass a block which accepts `context` to customize when to give a refresh
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doorkeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.4.0
4
+ version: 5.5.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Elias Philipp
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-05-11 00:00:00.000000000 Z
14
+ date: 2021-01-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: railties
@@ -103,14 +103,14 @@ dependencies:
103
103
  requirements:
104
104
  - - "~>"
105
105
  - !ruby/object:Gem::Version
106
- version: '5.0'
106
+ version: '6.0'
107
107
  type: :development
108
108
  prerelease: false
109
109
  version_requirements: !ruby/object:Gem::Requirement
110
110
  requirements:
111
111
  - - "~>"
112
112
  - !ruby/object:Gem::Version
113
- version: '5.0'
113
+ version: '6.0'
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: generator_spec
116
116
  requirement: !ruby/object:Gem::Requirement
@@ -194,6 +194,7 @@ files:
194
194
  - app/views/doorkeeper/applications/new.html.erb
195
195
  - app/views/doorkeeper/applications/show.html.erb
196
196
  - app/views/doorkeeper/authorizations/error.html.erb
197
+ - app/views/doorkeeper/authorizations/form_post.html.erb
197
198
  - app/views/doorkeeper/authorizations/new.html.erb
198
199
  - app/views/doorkeeper/authorizations/show.html.erb
199
200
  - app/views/doorkeeper/authorized_applications/_delete_form.html.erb
@@ -205,8 +206,13 @@ files:
205
206
  - lib/doorkeeper/config.rb
206
207
  - lib/doorkeeper/config/abstract_builder.rb
207
208
  - lib/doorkeeper/config/option.rb
209
+ - lib/doorkeeper/config/validations.rb
208
210
  - lib/doorkeeper/engine.rb
209
211
  - lib/doorkeeper/errors.rb
212
+ - lib/doorkeeper/grant_flow.rb
213
+ - lib/doorkeeper/grant_flow/fallback_flow.rb
214
+ - lib/doorkeeper/grant_flow/flow.rb
215
+ - lib/doorkeeper/grant_flow/registry.rb
210
216
  - lib/doorkeeper/grape/authorization_decorator.rb
211
217
  - lib/doorkeeper/grape/helpers.rb
212
218
  - lib/doorkeeper/helpers/controller.rb
@@ -316,7 +322,14 @@ metadata:
316
322
  source_code_uri: https://github.com/doorkeeper-gem/doorkeeper
317
323
  bug_tracker_uri: https://github.com/doorkeeper-gem/doorkeeper/issues
318
324
  documentation_uri: https://doorkeeper.gitbook.io/guides/
319
- post_install_message:
325
+ post_install_message: "Starting from 5.5.0.rc1 Doorkeeper requires client authentication
326
+ for Resource Owner Password Grant\nas stated in the OAuth RFC. You have to create
327
+ a new OAuth client (Doorkeeper::Application) if you didn't\nhave it before and use
328
+ client credentials in HTTP Basic auth if you previously used this grant flow without\nclient
329
+ authentication. \n\nTo opt out of this you could set the \"skip_client_authentication_for_password_grant\"
330
+ configuration option\nto \"true\", but note that this is in violation of the OAuth
331
+ spec and represents a security risk.\n\nRead https://github.com/doorkeeper-gem/doorkeeper/issues/561#issuecomment-612857163
332
+ for more details."
320
333
  rdoc_options: []
321
334
  require_paths:
322
335
  - lib
@@ -327,11 +340,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
327
340
  version: '2.4'
328
341
  required_rubygems_version: !ruby/object:Gem::Requirement
329
342
  requirements:
330
- - - ">="
343
+ - - ">"
331
344
  - !ruby/object:Gem::Version
332
- version: '0'
345
+ version: 1.3.1
333
346
  requirements: []
334
- rubygems_version: 3.0.2
347
+ rubygems_version: 3.1.2
335
348
  signing_key:
336
349
  specification_version: 4
337
350
  summary: OAuth 2 provider for Rails and Grape