doorkeeper 4.2.6 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of doorkeeper might be problematic. Click here for more details.

Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +19 -0
  3. data/.github/PULL_REQUEST_TEMPLATE.md +17 -0
  4. data/.gitignore +1 -1
  5. data/.hound.yml +2 -13
  6. data/.rubocop.yml +13 -0
  7. data/.travis.yml +13 -5
  8. data/Appraisals +6 -2
  9. data/CODE_OF_CONDUCT.md +46 -0
  10. data/Gemfile +1 -1
  11. data/NEWS.md +24 -0
  12. data/README.md +39 -9
  13. data/SECURITY.md +13 -0
  14. data/app/controllers/doorkeeper/application_controller.rb +1 -5
  15. data/app/controllers/doorkeeper/applications_controller.rb +14 -1
  16. data/app/controllers/doorkeeper/tokens_controller.rb +13 -1
  17. data/app/helpers/doorkeeper/dashboard_helper.rb +4 -2
  18. data/app/validators/redirect_uri_validator.rb +12 -2
  19. data/app/views/doorkeeper/applications/_form.html.erb +1 -1
  20. data/app/views/doorkeeper/authorized_applications/index.html.erb +0 -1
  21. data/config/locales/en.yml +3 -5
  22. data/doorkeeper.gemspec +4 -3
  23. data/gemfiles/rails_4_2.gemfile +6 -4
  24. data/gemfiles/rails_5_0.gemfile +4 -4
  25. data/gemfiles/rails_5_1.gemfile +6 -7
  26. data/gemfiles/rails_5_2.gemfile +12 -0
  27. data/gemfiles/rails_master.gemfile +14 -0
  28. data/lib/doorkeeper.rb +1 -0
  29. data/lib/doorkeeper/config.rb +55 -55
  30. data/lib/doorkeeper/engine.rb +3 -3
  31. data/lib/doorkeeper/grape/helpers.rb +13 -8
  32. data/lib/doorkeeper/helpers/controller.rb +8 -4
  33. data/lib/doorkeeper/models/access_token_mixin.rb +14 -7
  34. data/lib/doorkeeper/models/application_mixin.rb +11 -6
  35. data/lib/doorkeeper/models/concerns/expirable.rb +7 -5
  36. data/lib/doorkeeper/oauth/authorization/token.rb +22 -18
  37. data/lib/doorkeeper/oauth/authorization_code_request.rb +6 -1
  38. data/lib/doorkeeper/oauth/base_request.rb +5 -5
  39. data/lib/doorkeeper/oauth/client.rb +2 -2
  40. data/lib/doorkeeper/oauth/client/credentials.rb +2 -2
  41. data/lib/doorkeeper/oauth/error.rb +2 -2
  42. data/lib/doorkeeper/oauth/error_response.rb +1 -2
  43. data/lib/doorkeeper/oauth/forbidden_token_response.rb +1 -1
  44. data/lib/doorkeeper/oauth/invalid_token_response.rb +2 -3
  45. data/lib/doorkeeper/oauth/password_access_token_request.rb +1 -0
  46. data/lib/doorkeeper/oauth/refresh_token_request.rb +1 -0
  47. data/lib/doorkeeper/oauth/scopes.rb +18 -8
  48. data/lib/doorkeeper/oauth/token.rb +1 -1
  49. data/lib/doorkeeper/oauth/token_introspection.rb +128 -0
  50. data/lib/doorkeeper/orm/active_record.rb +20 -8
  51. data/lib/doorkeeper/orm/active_record/access_grant.rb +1 -1
  52. data/lib/doorkeeper/orm/active_record/access_token.rb +1 -23
  53. data/lib/doorkeeper/orm/active_record/application.rb +1 -1
  54. data/lib/doorkeeper/orm/active_record/base_record.rb +11 -0
  55. data/lib/doorkeeper/rails/helpers.rb +5 -6
  56. data/lib/doorkeeper/rails/routes.rb +9 -7
  57. data/lib/doorkeeper/request.rb +7 -1
  58. data/lib/doorkeeper/validations.rb +3 -2
  59. data/lib/doorkeeper/version.rb +13 -1
  60. data/lib/generators/doorkeeper/application_owner_generator.rb +11 -2
  61. data/lib/generators/doorkeeper/migration_generator.rb +13 -1
  62. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +7 -1
  63. data/lib/generators/doorkeeper/templates/{add_owner_to_application_migration.rb → add_owner_to_application_migration.rb.erb} +1 -1
  64. data/lib/generators/doorkeeper/templates/{add_previous_refresh_token_to_access_tokens.rb → add_previous_refresh_token_to_access_tokens.rb.erb} +1 -1
  65. data/lib/generators/doorkeeper/templates/initializer.rb +19 -3
  66. data/lib/generators/doorkeeper/templates/{migration.rb → migration.rb.erb} +1 -1
  67. data/spec/controllers/applications_controller_spec.rb +15 -4
  68. data/spec/controllers/authorizations_controller_spec.rb +5 -5
  69. data/spec/controllers/protected_resources_controller_spec.rb +28 -19
  70. data/spec/controllers/token_info_controller_spec.rb +17 -13
  71. data/spec/controllers/tokens_controller_spec.rb +138 -4
  72. data/spec/dummy/config/initializers/doorkeeper.rb +1 -1
  73. data/spec/dummy/config/initializers/{active_record_belongs_to_required_by_default.rb → new_framework_defaults.rb} +1 -1
  74. data/spec/dummy/config/initializers/secret_token.rb +0 -1
  75. data/spec/factories.rb +1 -1
  76. data/spec/generators/application_owner_generator_spec.rb +24 -5
  77. data/spec/generators/migration_generator_spec.rb +24 -3
  78. data/spec/generators/previous_refresh_token_generator_spec.rb +57 -0
  79. data/spec/grape/grape_integration_spec.rb +135 -0
  80. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  81. data/spec/lib/config_spec.rb +115 -12
  82. data/spec/lib/models/revocable_spec.rb +2 -2
  83. data/spec/lib/oauth/authorization_code_request_spec.rb +39 -11
  84. data/spec/lib/oauth/base_request_spec.rb +2 -7
  85. data/spec/lib/oauth/client_credentials/creator_spec.rb +1 -1
  86. data/spec/lib/oauth/client_credentials_integration_spec.rb +1 -1
  87. data/spec/lib/oauth/client_credentials_request_spec.rb +1 -0
  88. data/spec/lib/oauth/code_request_spec.rb +1 -3
  89. data/spec/lib/oauth/helpers/uri_checker_spec.rb +5 -0
  90. data/spec/lib/oauth/invalid_token_response_spec.rb +1 -1
  91. data/spec/lib/oauth/password_access_token_request_spec.rb +9 -3
  92. data/spec/lib/oauth/refresh_token_request_spec.rb +19 -7
  93. data/spec/lib/oauth/scopes_spec.rb +28 -1
  94. data/spec/lib/oauth/token_request_spec.rb +6 -8
  95. data/spec/lib/server_spec.rb +10 -0
  96. data/spec/models/doorkeeper/access_grant_spec.rb +1 -1
  97. data/spec/models/doorkeeper/access_token_spec.rb +72 -48
  98. data/spec/models/doorkeeper/application_spec.rb +51 -18
  99. data/spec/requests/applications/applications_request_spec.rb +5 -5
  100. data/spec/requests/endpoints/token_spec.rb +8 -1
  101. data/spec/requests/flows/authorization_code_spec.rb +1 -0
  102. data/spec/requests/flows/client_credentials_spec.rb +1 -1
  103. data/spec/requests/flows/implicit_grant_errors_spec.rb +2 -2
  104. data/spec/requests/flows/refresh_token_spec.rb +4 -4
  105. data/spec/requests/flows/revoke_token_spec.rb +15 -15
  106. data/spec/requests/protected_resources/metal_spec.rb +1 -1
  107. data/spec/requests/protected_resources/private_api_spec.rb +1 -1
  108. data/spec/routing/custom_controller_routes_spec.rb +4 -0
  109. data/spec/routing/default_routes_spec.rb +5 -1
  110. data/spec/spec_helper_integration.rb +15 -4
  111. data/spec/support/dependencies/factory_girl.rb +2 -2
  112. data/spec/support/helpers/access_token_request_helper.rb +1 -1
  113. data/spec/support/helpers/model_helper.rb +9 -4
  114. data/spec/support/helpers/request_spec_helper.rb +7 -3
  115. data/spec/support/helpers/url_helper.rb +8 -8
  116. data/spec/support/shared/controllers_shared_context.rb +2 -6
  117. data/spec/support/shared/models_shared_examples.rb +4 -4
  118. data/spec/validators/redirect_uri_validator_spec.rb +51 -6
  119. data/spec/version/version_spec.rb +15 -0
  120. metadata +42 -13
@@ -11,7 +11,8 @@ class RedirectUriValidator < ActiveModel::EachValidator
11
11
  else
12
12
  value.split.each do |val|
13
13
  uri = ::URI.parse(val)
14
- return if native_redirect_uri?(uri)
14
+ next if native_redirect_uri?(uri)
15
+ record.errors.add(attribute, :forbidden_uri) if forbidden_uri?(uri)
15
16
  record.errors.add(attribute, :fragment_present) unless uri.fragment.nil?
16
17
  record.errors.add(attribute, :relative_uri) if uri.scheme.nil? || uri.host.nil?
17
18
  record.errors.add(attribute, :secured_uri) if invalid_ssl_uri?(uri)
@@ -27,8 +28,17 @@ class RedirectUriValidator < ActiveModel::EachValidator
27
28
  self.class.native_redirect_uri.present? && uri.to_s == self.class.native_redirect_uri.to_s
28
29
  end
29
30
 
31
+ def forbidden_uri?(uri)
32
+ Doorkeeper.configuration.forbid_redirect_uri.call(uri)
33
+ end
34
+
30
35
  def invalid_ssl_uri?(uri)
31
36
  forces_ssl = Doorkeeper.configuration.force_ssl_in_redirect_uri
32
- forces_ssl && uri.try(:scheme) == 'http'
37
+
38
+ if forces_ssl.respond_to?(:call)
39
+ forces_ssl.call(uri)
40
+ else
41
+ forces_ssl && uri.try(:scheme) == 'http'
42
+ end
33
43
  end
34
44
  end
@@ -41,7 +41,7 @@
41
41
  <div class="form-group">
42
42
  <div class="col-sm-offset-2 col-sm-10">
43
43
  <%= f.submit t('doorkeeper.applications.buttons.submit'), class: "btn btn-primary" %>
44
- <%= link_to t('doorkeeper.applications.buttons.cancel'), oauth_applications_path, :class => "btn btn-default" %>
44
+ <%= link_to t('doorkeeper.applications.buttons.cancel'), oauth_applications_path, class: "btn btn-default" %>
45
45
  </div>
46
46
  </div>
47
47
  <% end %>
@@ -9,7 +9,6 @@
9
9
  <th><%= t('doorkeeper.authorized_applications.index.application') %></th>
10
10
  <th><%= t('doorkeeper.authorized_applications.index.created_at') %></th>
11
11
  <th></th>
12
- <th></th>
13
12
  </tr>
14
13
  </thead>
15
14
  <tbody>
@@ -13,6 +13,7 @@ en:
13
13
  invalid_uri: 'must be a valid URI.'
14
14
  relative_uri: 'must be an absolute URI.'
15
15
  secured_uri: 'must be an HTTPS/SSL URI.'
16
+ forbidden_uri: 'is forbidden by the server.'
16
17
 
17
18
  doorkeeper:
18
19
  applications:
@@ -28,7 +29,7 @@ en:
28
29
  error: 'Whoops! Check your form for possible errors'
29
30
  help:
30
31
  redirect_uri: 'Use one line per URI'
31
- native_redirect_uri: 'Use %{native_redirect_uri} for local tests'
32
+ native_redirect_uri: 'Use %{native_redirect_uri} if you want to add localhost URIs for development purposes'
32
33
  scopes: 'Separate scopes with spaces. Leave blank to use the default scopes.'
33
34
  edit:
34
35
  title: 'Edit application'
@@ -75,7 +76,7 @@ en:
75
76
  messages:
76
77
  # Common error messages
77
78
  invalid_request: 'The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed.'
78
- invalid_redirect_uri: 'The redirect uri included is not valid.'
79
+ invalid_redirect_uri: "The requested redirect uri is malformed or doesn't match client redirect URI."
79
80
  unauthorized_client: 'The client is not authorized to perform this request using this method.'
80
81
  access_denied: 'The resource owner or authorization server denied the request.'
81
82
  invalid_scope: 'The requested scope is invalid, unknown, or malformed.'
@@ -94,9 +95,6 @@ en:
94
95
  invalid_grant: 'The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.'
95
96
  unsupported_grant_type: 'The authorization grant type is not supported by the authorization server.'
96
97
 
97
- # Password Access token errors
98
- invalid_resource_owner: 'The provided resource owner credentials are not valid, or resource owner cannot be found'
99
-
100
98
  invalid_token:
101
99
  revoked: "The access token was revoked"
102
100
  expired: "The access token expired"
@@ -4,7 +4,7 @@ require "doorkeeper/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "doorkeeper"
7
- s.version = Doorkeeper::VERSION
7
+ s.version = Doorkeeper.gem_version
8
8
  s.authors = ["Felipe Elias Philipp", "Tute Costa", "Jon Moss"]
9
9
  s.email = %w(me@jonathanmoss.me)
10
10
  s.homepage = "https://github.com/doorkeeper-gem/doorkeeper"
@@ -21,8 +21,9 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_development_dependency "capybara"
23
23
  s.add_development_dependency "coveralls"
24
- s.add_development_dependency "database_cleaner", "~> 1.5.3"
25
- s.add_development_dependency "factory_girl", "~> 4.7.0"
24
+ s.add_development_dependency "grape"
25
+ s.add_development_dependency "database_cleaner", "~> 1.6"
26
+ s.add_development_dependency "factory_bot", "~> 4.8"
26
27
  s.add_development_dependency "generator_spec", "~> 0.9.3"
27
28
  s.add_development_dependency "rake", ">= 11.3.0"
28
29
  s.add_development_dependency "rspec-rails"
@@ -4,8 +4,10 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.2.0"
6
6
  gem "appraisal"
7
- gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
8
- gem "sqlite3", :platform => [:ruby, :mswin, :mingw, :x64_mingw]
9
- gem "tzinfo-data", :platforms => [:mingw, :mswin, :x64_mingw]
7
+ gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
8
+ gem "sqlite3", platform: [:ruby, :mswin, :mingw, :x64_mingw]
9
+ gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw]
10
+ # Older Grape requires Ruby >= 2.2.2
11
+ gem "grape", '~> 0.16', '< 0.19.2'
10
12
 
11
- gemspec :path => "../"
13
+ gemspec path: "../"
@@ -4,9 +4,9 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.0.0"
6
6
  gem "appraisal"
7
- gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
8
- gem "sqlite3", :platform => [:ruby, :mswin, :mingw, :x64_mingw]
9
- gem "tzinfo-data", :platforms => [:mingw, :mswin, :x64_mingw]
7
+ gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
8
+ gem "sqlite3", platforms: [:ruby, :mswin, :mingw, :x64_mingw]
9
+ gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw]
10
10
  gem "rspec-rails", "~> 3.5"
11
11
 
12
- gemspec :path => "../"
12
+ gemspec path: "../"
@@ -2,12 +2,11 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", :github => "rails/rails"
5
+ gem "rails", "~> 5.1.0"
6
6
  gem "appraisal"
7
- gem "activerecord-jdbcsqlite3-adapter", :platform => :jruby
8
- gem "sqlite3", :platform => [:ruby, :mswin, :mingw, :x64_mingw]
9
- gem "tzinfo-data", :platforms => [:mingw, :mswin, :x64_mingw]
10
- gem "arel", :github => "rails/arel"
11
- gem "rspec-rails", "~> 3.5"
7
+ gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
8
+ gem "sqlite3", platforms: [:ruby, :mswin, :mingw, :x64_mingw]
9
+ gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw]
10
+ gem "rspec-rails", "~> 3.7"
12
11
 
13
- gemspec :path => "../"
12
+ gemspec path: "../"
@@ -0,0 +1,12 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "5.2.0.rc1"
6
+ gem "appraisal"
7
+ gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
8
+ gem "sqlite3", platforms: [:ruby, :mswin, :mingw, :x64_mingw]
9
+ gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw]
10
+ gem "rspec-rails", "~> 3.7"
11
+
12
+ gemspec path: "../"
@@ -0,0 +1,14 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", git: 'https://github.com/rails/rails'
6
+ gem "arel", git: 'https://github.com/rails/arel'
7
+
8
+ gem "appraisal"
9
+ gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
10
+ gem "sqlite3", platform: [:ruby, :mswin, :mingw, :x64_mingw]
11
+ gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw]
12
+ gem "rspec-rails", "~> 3.7"
13
+
14
+ gemspec path: "../"
@@ -30,6 +30,7 @@ require 'doorkeeper/oauth/code_request'
30
30
  require 'doorkeeper/oauth/token_request'
31
31
  require 'doorkeeper/oauth/client'
32
32
  require 'doorkeeper/oauth/token'
33
+ require 'doorkeeper/oauth/token_introspection'
33
34
  require 'doorkeeper/oauth/invalid_token_response'
34
35
  require 'doorkeeper/oauth/forbidden_token_response'
35
36
 
@@ -59,12 +59,12 @@ doorkeeper.
59
59
  # @option opts[Boolean] :confirmation (false)
60
60
  # Set confirm_application_owner variable
61
61
  def enable_application_owner(opts = {})
62
- @config.instance_variable_set('@enable_application_owner', true)
62
+ @config.instance_variable_set(:@enable_application_owner, true)
63
63
  confirm_application_owner if opts[:confirmation].present? && opts[:confirmation]
64
64
  end
65
65
 
66
66
  def confirm_application_owner
67
- @config.instance_variable_set('@confirm_application_owner', true)
67
+ @config.instance_variable_set(:@confirm_application_owner, true)
68
68
  end
69
69
 
70
70
  # Define default access token scopes for your provider
@@ -72,7 +72,7 @@ doorkeeper.
72
72
  # @param scopes [Array] Default set of access (OAuth::Scopes.new)
73
73
  # token scopes
74
74
  def default_scopes(*scopes)
75
- @config.instance_variable_set('@default_scopes', OAuth::Scopes.from_array(scopes))
75
+ @config.instance_variable_set(:@default_scopes, OAuth::Scopes.from_array(scopes))
76
76
  end
77
77
 
78
78
  # Define default access token scopes for your provider
@@ -80,7 +80,7 @@ doorkeeper.
80
80
  # @param scopes [Array] Optional set of access (OAuth::Scopes.new)
81
81
  # token scopes
82
82
  def optional_scopes(*scopes)
83
- @config.instance_variable_set('@optional_scopes', OAuth::Scopes.from_array(scopes))
83
+ @config.instance_variable_set(:@optional_scopes, OAuth::Scopes.from_array(scopes))
84
84
  end
85
85
 
86
86
  # Change the way client credentials are retrieved from the request object.
@@ -90,7 +90,7 @@ doorkeeper.
90
90
  #
91
91
  # @param methods [Array] Define client credentials
92
92
  def client_credentials(*methods)
93
- @config.instance_variable_set('@client_credentials', methods)
93
+ @config.instance_variable_set(:@client_credentials, methods)
94
94
  end
95
95
 
96
96
  # Change the way access token is authenticated from the request object.
@@ -100,57 +100,19 @@ doorkeeper.
100
100
  #
101
101
  # @param methods [Array] Define access token methods
102
102
  def access_token_methods(*methods)
103
- @config.instance_variable_set('@access_token_methods', methods)
103
+ @config.instance_variable_set(:@access_token_methods, methods)
104
104
  end
105
105
 
106
106
  # Issue access tokens with refresh token (disabled by default)
107
107
  def use_refresh_token
108
- @config.instance_variable_set('@refresh_token_enabled', true)
109
- end
110
-
111
- # WWW-Authenticate Realm (default "Doorkeeper").
112
- #
113
- # @param realm [String] ("Doorkeeper") Authentication realm
114
- def realm(realm)
115
- @config.instance_variable_set('@realm', realm)
108
+ @config.instance_variable_set(:@refresh_token_enabled, true)
116
109
  end
117
110
 
118
111
  # Reuse access token for the same resource owner within an application
119
112
  # (disabled by default)
120
113
  # Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383
121
114
  def reuse_access_token
122
- @config.instance_variable_set("@reuse_access_token", true)
123
- end
124
-
125
- # Forces the usage of the HTTPS protocol in non-native redirect uris
126
- # (enabled by default in non-development environments). OAuth2
127
- # delegates security in communication to the HTTPS protocol so it is
128
- # wise to keep this enabled.
129
- #
130
- # @param [Boolean] boolean value for the parameter, true by default in
131
- # non-development environment
132
- def force_ssl_in_redirect_uri(boolean)
133
- @config.instance_variable_set("@force_ssl_in_redirect_uri", boolean)
134
- end
135
-
136
- # Use a custom class for generating the access token.
137
- # https://github.com/doorkeeper-gem/doorkeeper#custom-access-token-generator
138
- #
139
- # @param access_token_generator [String]
140
- # the name of the access token generator class
141
- def access_token_generator(access_token_generator)
142
- @config.instance_variable_set(
143
- '@access_token_generator', access_token_generator
144
- )
145
- end
146
-
147
- # The controller Doorkeeper::ApplicationController inherits from.
148
- # Defaults to ActionController::Base.
149
- # https://github.com/doorkeeper-gem/doorkeeper#custom-base-controller
150
- #
151
- # @param base_controller [String] the name of the base controller
152
- def base_controller(base_controller)
153
- @config.instance_variable_set('@base_controller', base_controller)
115
+ @config.instance_variable_set(:@reuse_access_token, true)
154
116
  end
155
117
  end
156
118
 
@@ -210,10 +172,6 @@ doorkeeper.
210
172
 
211
173
  public attribute
212
174
  end
213
-
214
- def extended(base)
215
- base.send(:private, :option)
216
- end
217
175
  end
218
176
 
219
177
  extend Option
@@ -221,15 +179,17 @@ doorkeeper.
221
179
  option :resource_owner_authenticator,
222
180
  as: :authenticate_resource_owner,
223
181
  default: (lambda do |_routes|
224
- logger.warn(I18n.translate('doorkeeper.errors.messages.resource_owner_authenticator_not_configured'))
182
+ ::Rails.logger.warn(I18n.t('doorkeeper.errors.messages.resource_owner_authenticator_not_configured'))
225
183
  nil
226
184
  end)
185
+
227
186
  option :admin_authenticator,
228
187
  as: :authenticate_admin,
229
188
  default: ->(_routes) {}
189
+
230
190
  option :resource_owner_from_credentials,
231
191
  default: (lambda do |_routes|
232
- warn(I18n.translate('doorkeeper.errors.messages.credential_flow_not_configured'))
192
+ ::Rails.logger.warn(I18n.t('doorkeeper.errors.messages.credential_flow_not_configured'))
233
193
  nil
234
194
  end)
235
195
 
@@ -240,11 +200,51 @@ doorkeeper.
240
200
  option :orm, default: :active_record
241
201
  option :native_redirect_uri, default: 'urn:ietf:wg:oauth:2.0:oob'
242
202
  option :active_record_options, default: {}
203
+ option :grant_flows, default: %w[authorization_code client_credentials]
204
+
205
+ # Allows to forbid specific Application redirect URI's by custom rules.
206
+ # Doesn't forbid any URI by default.
207
+ #
208
+ # @param forbid_redirect_uri [Proc] Block or any object respond to #call
209
+ #
210
+ option :forbid_redirect_uri, default: ->(_uri) { false }
211
+
212
+ # WWW-Authenticate Realm (default "Doorkeeper").
213
+ #
214
+ # @param realm [String] ("Doorkeeper") Authentication realm
215
+ #
243
216
  option :realm, default: 'Doorkeeper'
217
+
218
+ # Forces the usage of the HTTPS protocol in non-native redirect uris
219
+ # (enabled by default in non-development environments). OAuth2
220
+ # delegates security in communication to the HTTPS protocol so it is
221
+ # wise to keep this enabled.
222
+ #
223
+ # @param [Boolean] boolean_or_block value for the parameter, true by default in
224
+ # non-development environment
225
+ #
226
+ # @yield [uri] Conditional usage of SSL redirect uris.
227
+ # @yieldparam [URI] Redirect URI
228
+ # @yieldreturn [Boolean] Indicates necessity of usage of the HTTPS protocol
229
+ # in non-native redirect uris
230
+ #
244
231
  option :force_ssl_in_redirect_uri, default: !Rails.env.development?
245
- option :grant_flows, default: %w(authorization_code client_credentials)
232
+
233
+
234
+ # Use a custom class for generating the access token.
235
+ # https://github.com/doorkeeper-gem/doorkeeper#custom-access-token-generator
236
+ #
237
+ # @param access_token_generator [String]
238
+ # the name of the access token generator class
239
+ #
246
240
  option :access_token_generator,
247
241
  default: 'Doorkeeper::OAuth::Helpers::UniqueToken'
242
+
243
+ # The controller Doorkeeper::ApplicationController inherits from.
244
+ # Defaults to ActionController::Base.
245
+ # https://github.com/doorkeeper-gem/doorkeeper#custom-base-controller
246
+ #
247
+ # @param base_controller [String] the name of the base controller
248
248
  option :base_controller,
249
249
  default: 'ActionController::Base'
250
250
 
@@ -278,11 +278,11 @@ doorkeeper.
278
278
  end
279
279
 
280
280
  def client_credentials_methods
281
- @client_credentials ||= [:from_basic, :from_params]
281
+ @client_credentials ||= %i[from_basic from_params]
282
282
  end
283
283
 
284
284
  def access_token_methods
285
- @access_token_methods ||= [:from_bearer_authorization, :from_access_token_param, :from_bearer_param]
285
+ @access_token_methods ||= %i[from_bearer_authorization from_access_token_param from_bearer_param]
286
286
  end
287
287
 
288
288
  def authorization_response_types
@@ -1,7 +1,7 @@
1
1
  module Doorkeeper
2
2
  class Engine < Rails::Engine
3
3
  initializer "doorkeeper.params.filter" do |app|
4
- parameters = %w(client_secret code authentication_token access_token refresh_token)
4
+ parameters = %w[client_secret code authentication_token access_token refresh_token]
5
5
  app.config.filter_parameters << /^(#{Regexp.union parameters})$/
6
6
  end
7
7
 
@@ -17,10 +17,10 @@ module Doorkeeper
17
17
 
18
18
  if defined?(Sprockets) && Sprockets::VERSION.chr.to_i >= 4
19
19
  initializer 'doorkeeper.assets.precompile' do |app|
20
- app.config.assets.precompile += %w(
20
+ app.config.assets.precompile += %w[
21
21
  doorkeeper/application.css
22
22
  doorkeeper/admin/application.css
23
- )
23
+ ]
24
24
  end
25
25
  end
26
26
  end
@@ -9,7 +9,7 @@ module Doorkeeper
9
9
 
10
10
  # endpoint specific scopes > parameter scopes > default scopes
11
11
  def doorkeeper_authorize!(*scopes)
12
- endpoint_scopes = env["api.endpoint"].route_setting(:scopes)
12
+ endpoint_scopes = endpoint.route_setting(:scopes) || endpoint.options[:route_options][:scopes]
13
13
  scopes = if endpoint_scopes
14
14
  Doorkeeper::OAuth::Scopes.from_array(endpoint_scopes)
15
15
  elsif scopes && !scopes.empty?
@@ -20,18 +20,16 @@ module Doorkeeper
20
20
  end
21
21
 
22
22
  def doorkeeper_render_error_with(error)
23
- status_code = case error.status
24
- when :unauthorized
25
- 401
26
- when :forbidden
27
- 403
28
- end
29
-
23
+ status_code = error_status_codes[error.status]
30
24
  error!({ error: error.description }, status_code, error.headers)
31
25
  end
32
26
 
33
27
  private
34
28
 
29
+ def endpoint
30
+ env['api.endpoint']
31
+ end
32
+
35
33
  def doorkeeper_token
36
34
  @_doorkeeper_token ||= OAuth::Token.authenticate(
37
35
  decorated_request,
@@ -42,6 +40,13 @@ module Doorkeeper
42
40
  def decorated_request
43
41
  AuthorizationDecorator.new(request)
44
42
  end
43
+
44
+ def error_status_codes
45
+ {
46
+ unauthorized: 401,
47
+ forbidden: 403
48
+ }
49
+ end
45
50
  end
46
51
  end
47
52
  end