doorkeeper 5.5.4 → 5.6.4

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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +47 -3
  3. data/README.md +4 -3
  4. data/app/controllers/doorkeeper/authorizations_controller.rb +3 -1
  5. data/app/controllers/doorkeeper/tokens_controller.rb +8 -5
  6. data/app/views/doorkeeper/authorizations/new.html.erb +16 -16
  7. data/lib/doorkeeper/config/abstract_builder.rb +1 -1
  8. data/lib/doorkeeper/config/validations.rb +3 -3
  9. data/lib/doorkeeper/config.rb +35 -54
  10. data/lib/doorkeeper/engine.rb +10 -3
  11. data/lib/doorkeeper/helpers/controller.rb +1 -1
  12. data/lib/doorkeeper/models/access_token_mixin.rb +6 -6
  13. data/lib/doorkeeper/models/concerns/expiration_time_sql_math.rb +88 -0
  14. data/lib/doorkeeper/models/concerns/polymorphic_resource_owner.rb +30 -0
  15. data/lib/doorkeeper/oauth/authorization/token.rb +7 -1
  16. data/lib/doorkeeper/oauth/base_request.rb +1 -1
  17. data/lib/doorkeeper/oauth/client_credentials/creator.rb +6 -5
  18. data/lib/doorkeeper/oauth/client_credentials/validator.rb +1 -2
  19. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +3 -3
  20. data/lib/doorkeeper/oauth/token_introspection.rb +1 -1
  21. data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +0 -6
  22. data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +21 -4
  23. data/lib/doorkeeper/orm/active_record/mixins/application.rb +12 -1
  24. data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +2 -2
  25. data/lib/doorkeeper/orm/active_record/stale_records_cleaner.rb +5 -2
  26. data/lib/doorkeeper/orm/active_record.rb +30 -37
  27. data/lib/doorkeeper/rails/routes.rb +12 -3
  28. data/lib/doorkeeper/rake/setup.rake +0 -5
  29. data/lib/doorkeeper/version.rb +1 -1
  30. data/lib/doorkeeper.rb +73 -5
  31. data/lib/generators/doorkeeper/templates/initializer.rb +4 -3
  32. data/lib/generators/doorkeeper/templates/migration.rb.erb +14 -4
  33. metadata +21 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55c17555b9591b1a06b8164b0508ab733df8dca59e4b555e1dac3b3cc7a1112e
4
- data.tar.gz: 56fd2b8475c97f0bc755086cc22ee1aa14d2ac47263f0e218f3cf4f9f80d5b38
3
+ metadata.gz: e1f7bb9a1bb5e08c4b7c3ccb920bef61fbbd1dc0b11f76bba3a3d76a6fc8eeed
4
+ data.tar.gz: 456ffe74dac831f3b797565041e46ecf241fb4cfc597d0bc39aa7a3893abeecb
5
5
  SHA512:
6
- metadata.gz: b21d497b70266436f0446eec977f9ff074f646c0cdf417e08c8806529474ea91d112f0f1357a614f9e136b0dd042d665f7ea7325740254770ff01469df595390
7
- data.tar.gz: eb23ac65993cf89d82b66e5616b231d58fd0ac928486354a2bc36fdf7173fb3ba807f434f85a45f4ea6d1600847b46bdd5ad76ea9d317c16908a114b18fdb94a
6
+ metadata.gz: 6e23087c44495ce91c7e23f1bf8cd771dc82bdb92ffa1cac8f8bef2e42919bf8eea1ac86b1ed76580537c4b5a6b2ba571452470677259fb61e4be0e151091ad7
7
+ data.tar.gz: fcafc844c46bab18f03d5dd7e8bd345111fb57530275adbf8d9954f8e8c1436b29ded79e15f6321e9f86c845836b713c65aca23398114cfdb5c77e9b87a01647
data/CHANGELOG.md CHANGED
@@ -9,6 +9,50 @@ User-visible changes worth mentioning.
9
9
 
10
10
  - [#ID] Add your PR description here.
11
11
 
12
+ # 5.6.4
13
+
14
+ - [#1633] Apply ORM configuration in #to_prepare block to avoid autoloading errors.
15
+
16
+ # 5.6.3
17
+
18
+ - [#1622] Drop support for Rubies 2.5 and 2.6
19
+ - [#1605] Fix URI validation for Ruby 3.2+.
20
+ - [#1625] Exclude endless access tokens from `StaleRecordsCleaner`.
21
+ - [#1626] Remove deprecated `active_record_options` config option.
22
+ - [#1631] Fix regression with redirect behavior after token lookup optimizations (redirect to app URI when found).
23
+ - [#1630] Special case unique index creation for refresh_token on SQL Server.
24
+ - [#1627] Lazy evaluate Doorkeeper config when loading files and executing initializers.
25
+
26
+ ## 5.6.2
27
+
28
+ - [#1604] Fix fetching of the application when custom application_class defined.
29
+
30
+ ## 5.6.1
31
+
32
+ - [#1593] Add support for Trilogy ActiveRecord adapter.
33
+ - [#1597] Add optional support to use the url path for the native authorization code flow. Ports forward [#1143] from 4.4.3
34
+ - [#1599] Remove unnecessarily re-fetch of application object when creating an access token.
35
+
36
+ ## 5.6.0
37
+
38
+ - [#1581] Consider `token_type_hint` when searching for access token in TokensController to avoid extra database calls.
39
+
40
+ ## 5.6.0.rc2
41
+
42
+ - [#1558] Fixed bug: able to obtain a token with default scopes even if they are not present in the
43
+ application scopes when using client credentials.
44
+ - [#1567] Only filter `code` parameter if authorization_code grant flow is enabled.
45
+
46
+ ## 5.6.0.rc1
47
+
48
+ - [#1551] Change lazy loading for ORM to be Ruby standard autoload.
49
+ - [#1552] Remove duplicate IDs on Auth form to improve accessibility.
50
+ - [#1542] Improve performance of `Doorkeeper::AccessToken#matching_token_for` using database specific SQL time math.
51
+
52
+ **[IMPORTANT]**: API of the `Doorkeeper::AccessToken#matching_token_for` method has changed and now it returns
53
+ only **active** access tokens (previously they were just not revoked). Please remember that the idea of the
54
+ `reuse_access_token` option is to check for existing _active_ token (see configuration option description).
55
+
12
56
  ## 5.5.4
13
57
 
14
58
  - [#1535] Revert changes introduced in #1528 to allow query params in `redirect_uri` as per the spec.
@@ -25,7 +69,7 @@ User-visible changes worth mentioning.
25
69
  - [#1502] Drop support for Ruby 2.4 because of EOL.
26
70
  - [#1504] Updated the url fragment in the comment for code documentation.
27
71
  - [#1512] Fix form behavior when response mode is form_post.
28
- - [#1511] Fix that authorization code is returned by fragment if response_mode is fragament.
72
+ - [#1511] Fix that authorization code is returned by fragment if response_mode is fragment.
29
73
 
30
74
  ## 5.5.1
31
75
 
@@ -254,7 +298,7 @@ User-visible changes worth mentioning.
254
298
  - [#1237] Allow to set blank redirect URI if Doorkeeper configured to use redirect URI-less grant flows.
255
299
  - [#1234] Fix `StaleRecordsCleaner` to properly work with big amount of records.
256
300
  - [#1228] Allow to explicitly set non-expiring tokens in `custom_access_token_expires_in` configuration
257
- option using `Float::INIFINITY` return value.
301
+ option using `Float::INFINITY` return value.
258
302
  - [#1224] Do not try to store token if not found by fallback hashing strategy.
259
303
  - [#1223] Update Hound/Rubocop rules, correct Doorkeeper codebase to follow style-guides.
260
304
  - [#1220] Drop Rails 4.2 & Ruby < 2.4 support.
@@ -339,7 +383,7 @@ User-visible changes worth mentioning.
339
383
  - [#1116] `AccessGrant`s will now be revoked along with `AccessToken`s when
340
384
  hitting the `AuthorizedApplicationController#destroy` route.
341
385
  - [#1114] Make token info endpoint's attributes consistent with token creation
342
- - [#1108] Simple formating of callback URLs when listing oauth applications
386
+ - [#1108] Simple formatting of callback URLs when listing oauth applications
343
387
  - [#1106] Restrict access to AdminController with 'Forbidden 403' if admin_authenticator is not
344
388
  configured by developers.
345
389
 
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
1
  # Doorkeeper — awesome OAuth 2 provider for your Rails / Grape app.
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/doorkeeper.svg)](https://rubygems.org/gems/doorkeeper)
4
- [![Build Status](https://app.travis-ci.com/doorkeeper-gem/doorkeeper.svg?branch=main)](https://app.travis-ci.com/doorkeeper-gem/doorkeeper)
4
+ [![CI](https://github.com/doorkeeper-gem/doorkeeper/actions/workflows/ci.yml/badge.svg)](https://github.com/doorkeeper-gem/doorkeeper/actions/workflows/ci.yml)
5
5
  [![Code Climate](https://codeclimate.com/github/doorkeeper-gem/doorkeeper.svg)](https://codeclimate.com/github/doorkeeper-gem/doorkeeper)
6
6
  [![Coverage Status](https://coveralls.io/repos/github/doorkeeper-gem/doorkeeper/badge.svg?branch=main)](https://coveralls.io/github/doorkeeper-gem/doorkeeper?branch=main)
7
- [![Security](https://hakiri.io/github/doorkeeper-gem/doorkeeper/main.svg)](https://hakiri.io/github/doorkeeper-gem/doorkeeper/main)
8
7
  [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
9
8
  [![GuardRails badge](https://badges.guardrails.io/doorkeeper-gem/doorkeeper.svg?token=66768ce8f6995814df81f65a2cff40f739f688492704f973e62809e15599bb62)](https://dashboard.guardrails.io/default/gh/doorkeeper-gem/doorkeeper)
10
9
  [![Dependabot](https://img.shields.io/badge/dependabot-enabled-success.svg)](https://dependabot.com)
@@ -106,6 +105,8 @@ Extensions that are not included by default and can be installed separately.
106
105
  | JWT Token support | [doorkeeper-gem/doorkeeper-jwt](https://github.com/doorkeeper-gem/doorkeeper-jwt) |
107
106
  | Assertion grant extension | [doorkeeper-gem/doorkeeper-grants\_assertion](https://github.com/doorkeeper-gem/doorkeeper-grants_assertion) |
108
107
  | I18n translations | [doorkeeper-gem/doorkeeper-i18n](https://github.com/doorkeeper-gem/doorkeeper-i18n) |
108
+ | CIBA - Client Initiated Backchannel Authentication Flow extension | [doorkeeper-ciba](https://github.com/autoseg/doorkeeper-ciba) |
109
+ | Device Authorization Grant | [doorkeeper-device_authorization_grant](https://github.com/exop-group/doorkeeper-device_authorization_grant) |
109
110
 
110
111
  ## Example Applications
111
112
 
@@ -188,4 +189,4 @@ contributors](https://github.com/doorkeeper-gem/doorkeeper/graphs/contributors)!
188
189
 
189
190
  ## License
190
191
 
191
- MIT License. Copyright 2011 Applicake.
192
+ MIT License. Created in Applicake. Maintained by the community.
@@ -24,7 +24,7 @@ module Doorkeeper
24
24
 
25
25
  def render_success
26
26
  if skip_authorization? || matching_token?
27
- redirect_or_render authorize_response
27
+ redirect_or_render(authorize_response)
28
28
  elsif Doorkeeper.configuration.api_only
29
29
  render json: pre_auth
30
30
  else
@@ -41,6 +41,8 @@ module Doorkeeper
41
41
  end
42
42
  end
43
43
 
44
+ # Active access token issued for the same client and resource owner with
45
+ # the same set of the scopes exists?
44
46
  def matching_token?
45
47
  Doorkeeper.config.access_token_model.matching_token_for(
46
48
  pre_auth.client,
@@ -30,6 +30,7 @@ module Doorkeeper
30
30
  end
31
31
  end
32
32
 
33
+ # OAuth 2.0 Token Introspection - https://datatracker.ietf.org/doc/html/rfc7662
33
34
  def introspect
34
35
  introspection = OAuth::TokenIntrospection.new(server, token)
35
36
 
@@ -115,12 +116,14 @@ module Doorkeeper
115
116
  token.revoke if token&.accessible?
116
117
  end
117
118
 
118
- # Doorkeeper does not use the token_type_hint logic described in the
119
- # RFC 7009 due to the refresh token implementation that is a field in
120
- # the access token model.
121
119
  def token
122
- @token ||= Doorkeeper.config.access_token_model.by_token(params["token"]) ||
123
- Doorkeeper.config.access_token_model.by_refresh_token(params["token"])
120
+ @token ||=
121
+ if params[:token_type_hint] == "refresh_token"
122
+ Doorkeeper.config.access_token_model.by_refresh_token(params["token"])
123
+ else
124
+ Doorkeeper.config.access_token_model.by_token(params["token"]) ||
125
+ Doorkeeper.config.access_token_model.by_refresh_token(params["token"])
126
+ end
124
127
  end
125
128
 
126
129
  def strategy
@@ -21,25 +21,25 @@
21
21
 
22
22
  <div class="actions">
23
23
  <%= form_tag oauth_authorization_path, method: :post do %>
24
- <%= hidden_field_tag :client_id, @pre_auth.client.uid %>
25
- <%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri %>
26
- <%= hidden_field_tag :state, @pre_auth.state %>
27
- <%= hidden_field_tag :response_type, @pre_auth.response_type %>
28
- <%= hidden_field_tag :response_mode, @pre_auth.response_mode %>
29
- <%= hidden_field_tag :scope, @pre_auth.scope %>
30
- <%= hidden_field_tag :code_challenge, @pre_auth.code_challenge %>
31
- <%= hidden_field_tag :code_challenge_method, @pre_auth.code_challenge_method %>
24
+ <%= hidden_field_tag :client_id, @pre_auth.client.uid, id: nil %>
25
+ <%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri, id: nil %>
26
+ <%= hidden_field_tag :state, @pre_auth.state, id: nil %>
27
+ <%= hidden_field_tag :response_type, @pre_auth.response_type, id: nil %>
28
+ <%= hidden_field_tag :response_mode, @pre_auth.response_mode, id: nil %>
29
+ <%= hidden_field_tag :scope, @pre_auth.scope, id: nil %>
30
+ <%= hidden_field_tag :code_challenge, @pre_auth.code_challenge, id: nil %>
31
+ <%= hidden_field_tag :code_challenge_method, @pre_auth.code_challenge_method, id: nil %>
32
32
  <%= submit_tag t('doorkeeper.authorizations.buttons.authorize'), class: "btn btn-success btn-lg btn-block" %>
33
33
  <% end %>
34
34
  <%= form_tag oauth_authorization_path, method: :delete do %>
35
- <%= hidden_field_tag :client_id, @pre_auth.client.uid %>
36
- <%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri %>
37
- <%= hidden_field_tag :state, @pre_auth.state %>
38
- <%= hidden_field_tag :response_type, @pre_auth.response_type %>
39
- <%= hidden_field_tag :response_mode, @pre_auth.response_mode %>
40
- <%= hidden_field_tag :scope, @pre_auth.scope %>
41
- <%= hidden_field_tag :code_challenge, @pre_auth.code_challenge %>
42
- <%= hidden_field_tag :code_challenge_method, @pre_auth.code_challenge_method %>
35
+ <%= hidden_field_tag :client_id, @pre_auth.client.uid, id: nil %>
36
+ <%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri, id: nil %>
37
+ <%= hidden_field_tag :state, @pre_auth.state, id: nil %>
38
+ <%= hidden_field_tag :response_type, @pre_auth.response_type, id: nil %>
39
+ <%= hidden_field_tag :response_mode, @pre_auth.response_mode, id: nil %>
40
+ <%= hidden_field_tag :scope, @pre_auth.scope, id: nil %>
41
+ <%= hidden_field_tag :code_challenge, @pre_auth.code_challenge, id: nil %>
42
+ <%= hidden_field_tag :code_challenge_method, @pre_auth.code_challenge_method, id: nil %>
43
43
  <%= submit_tag t('doorkeeper.authorizations.buttons.deny'), class: "btn btn-danger btn-lg btn-block" %>
44
44
  <% end %>
45
45
  </div>
@@ -12,7 +12,7 @@ module Doorkeeper
12
12
  #
13
13
  def initialize(config = Config.new, &block)
14
14
  @config = config
15
- instance_eval(&block)
15
+ instance_eval(&block) if block_given?
16
16
  end
17
17
 
18
18
  # Builds and validates configuration.
@@ -24,8 +24,8 @@ module Doorkeeper
24
24
  return if !reuse_access_token || strategy.allows_restoring_secrets?
25
25
 
26
26
  ::Rails.logger.warn(
27
- "You have configured both reuse_access_token " \
28
- "AND strategy strategy '#{strategy}' that cannot restore tokens. " \
27
+ "[DOORKEEPER] You have configured both reuse_access_token " \
28
+ "AND '#{strategy}' strategy which cannot restore tokens. " \
29
29
  "This combination is unsupported. reuse_access_token will be disabled",
30
30
  )
31
31
  @reuse_access_token = false
@@ -43,7 +43,7 @@ module Doorkeeper
43
43
  (token_reuse_limit > 0 && token_reuse_limit <= 100)
44
44
 
45
45
  ::Rails.logger.warn(
46
- "You have configured an invalid value for token_reuse_limit option. " \
46
+ "[DOORKEEPER] You have configured an invalid value for token_reuse_limit option. " \
47
47
  "It will be set to default 100",
48
48
  )
49
49
  @token_reuse_limit = 100
@@ -5,59 +5,11 @@ require "doorkeeper/config/option"
5
5
  require "doorkeeper/config/validations"
6
6
 
7
7
  module Doorkeeper
8
- # Defines a MissingConfiguration error for a missing Doorkeeper configuration
9
- #
10
- class MissingConfiguration < StandardError
11
- def initialize
12
- super("Configuration for doorkeeper missing. Do you have doorkeeper initializer?")
13
- end
14
- end
15
-
16
8
  # Doorkeeper option DSL could be reused in extensions to build their own
17
9
  # configurations. To use the Option DSL gems need to define `builder_class` method
18
10
  # that returns configuration Builder class. This exception raises when they don't
19
11
  # define it.
20
12
  #
21
- class MissingConfigurationBuilderClass < StandardError; end
22
-
23
- class << self
24
- def configure(&block)
25
- @config = Config::Builder.new(&block).build
26
- setup_orm_adapter
27
- setup_orm_models
28
- setup_application_owner if @config.enable_application_owner?
29
- @config
30
- end
31
-
32
- # @return [Doorkeeper::Config] configuration instance
33
- #
34
- def configuration
35
- @config || (raise MissingConfiguration)
36
- end
37
-
38
- alias config configuration
39
-
40
- def setup_orm_adapter
41
- @orm_adapter = "doorkeeper/orm/#{configuration.orm}".classify.constantize
42
- rescue NameError => e
43
- raise e, "ORM adapter not found (#{configuration.orm})", <<-ERROR_MSG.strip_heredoc
44
- [DOORKEEPER] ORM adapter not found (#{configuration.orm}), or there was an error
45
- trying to load it.
46
-
47
- You probably need to add the related gem for this adapter to work with
48
- doorkeeper.
49
- ERROR_MSG
50
- end
51
-
52
- def setup_orm_models
53
- @orm_adapter.initialize_models!
54
- end
55
-
56
- def setup_application_owner
57
- @orm_adapter.initialize_application_owner!
58
- end
59
- end
60
-
61
13
  class Config
62
14
  # Default Doorkeeper configuration builder
63
15
  class Builder < AbstractBuilder
@@ -137,6 +89,15 @@ module Doorkeeper
137
89
  @config.instance_variable_set(:@reuse_access_token, true)
138
90
  end
139
91
 
92
+ # Choose to use the url path for native autorization codes
93
+ # Enabling this flag sets the authorization code response route for
94
+ # native redirect uris to oauth/authorize/<code>. The default is
95
+ # oauth/authorize/native?code=<code>.
96
+ # Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/1143
97
+ def use_url_path_for_native_authorization
98
+ @config.instance_variable_set(:@use_url_path_for_native_authorization, true)
99
+ end
100
+
140
101
  # TODO: maybe make it more generic for other flows too?
141
102
  # Only allow one valid access token obtained via client credentials
142
103
  # per client. If a new access token is obtained before the old one
@@ -293,10 +254,6 @@ module Doorkeeper
293
254
  option :skip_client_authentication_for_password_grant,
294
255
  default: false
295
256
 
296
- option :active_record_options,
297
- default: {},
298
- deprecated: { message: "Customize Doorkeeper models instead" }
299
-
300
257
  # Hook to allow arbitrary user-client authorization
301
258
  option :authorize_resource_owner_for_client,
302
259
  default: ->(_client, _resource_owner) { true }
@@ -364,11 +321,20 @@ module Doorkeeper
364
321
  option :access_token_generator,
365
322
  default: "Doorkeeper::OAuth::Helpers::UniqueToken"
366
323
 
324
+ # Use a custom class for generating the application secret.
325
+ # https://doorkeeper.gitbook.io/guides/configuration/other-configurations#custom-application-secret-generator
326
+ #
327
+ # @param application_secret_generator [String]
328
+ # the name of the application secret generator class
329
+ #
330
+ option :application_secret_generator,
331
+ default: "Doorkeeper::OAuth::Helpers::UniqueToken"
332
+
367
333
  # Default access token generator is a SecureRandom class from Ruby stdlib.
368
334
  # This option defines which method will be used to generate a unique token value.
369
335
  #
370
- # @param access_token_generator [String]
371
- # the name of the access token generator class
336
+ # @param default_generator_method [Symbol]
337
+ # the method name of the default access token generator
372
338
  #
373
339
  option :default_generator_method, default: :urlsafe_base64
374
340
 
@@ -441,6 +407,16 @@ module Doorkeeper
441
407
  :token_secret_fallback_strategy,
442
408
  :application_secret_fallback_strategy
443
409
 
410
+ def clear_cache!
411
+ %i[
412
+ application_model
413
+ access_token_model
414
+ access_grant_model
415
+ ].each do |var|
416
+ remove_instance_variable("@#{var}") if instance_variable_defined?("@#{var}")
417
+ end
418
+ end
419
+
444
420
  # Doorkeeper Access Token model class.
445
421
  #
446
422
  # @return [ActiveRecord::Base, Mongoid::Document, Sequel::Model]
@@ -581,6 +557,11 @@ module Doorkeeper
581
557
  def deprecated_token_grant_types_resolver
582
558
  @deprecated_token_grant_types ||= calculate_token_grant_types
583
559
  end
560
+
561
+ def native_authorization_code_route
562
+ @use_url_path_for_native_authorization = false unless defined?(@use_url_path_for_native_authorization)
563
+ @use_url_path_for_native_authorization ? '/:code' : '/native'
564
+ end
584
565
 
585
566
  # [NOTE]: deprecated and will be removed soon
586
567
  def deprecated_authorization_flows
@@ -2,9 +2,12 @@
2
2
 
3
3
  module Doorkeeper
4
4
  class Engine < Rails::Engine
5
- initializer "doorkeeper.params.filter" do |app|
6
- parameters = %w[client_secret code authentication_token access_token refresh_token]
7
- app.config.filter_parameters << /^(#{Regexp.union(parameters)})$/
5
+ initializer "doorkeeper.params.filter", after: :load_config_initializers do |app|
6
+ if Doorkeeper.configured?
7
+ parameters = %w[client_secret authentication_token access_token refresh_token]
8
+ parameters << "code" if Doorkeeper.config.grant_flows.include?("authorization_code")
9
+ app.config.filter_parameters << /^(#{Regexp.union(parameters)})$/
10
+ end
8
11
  end
9
12
 
10
13
  initializer "doorkeeper.routes" do
@@ -17,6 +20,10 @@ module Doorkeeper
17
20
  end
18
21
  end
19
22
 
23
+ config.to_prepare do
24
+ Doorkeeper.run_orm_hooks
25
+ end
26
+
20
27
  if defined?(Sprockets) && Sprockets::VERSION.chr.to_i >= 4
21
28
  initializer "doorkeeper.assets.precompile" do |app|
22
29
  # Force users to use:
@@ -82,7 +82,7 @@ module Doorkeeper
82
82
  end
83
83
 
84
84
  def x_www_form_urlencoded?
85
- request.content_type == "application/x-www-form-urlencoded"
85
+ request.media_type == "application/x-www-form-urlencoded"
86
86
  end
87
87
  end
88
88
  end
@@ -13,6 +13,7 @@ module Doorkeeper
13
13
  include Models::SecretStorable
14
14
  include Models::Scopes
15
15
  include Models::ResourceOwnerable
16
+ include Models::ExpirationTimeSqlMath
16
17
 
17
18
  module ClassMethods
18
19
  # Returns an instance of the Doorkeeper::AccessToken with
@@ -86,8 +87,9 @@ module Doorkeeper
86
87
  # @return [Doorkeeper::AccessToken, nil] Access Token instance or
87
88
  # nil if matching record was not found
88
89
  #
89
- def matching_token_for(application, resource_owner, scopes)
90
+ def matching_token_for(application, resource_owner, scopes, include_expired: true)
90
91
  tokens = authorized_tokens_for(application&.id, resource_owner)
92
+ tokens = tokens.not_expired unless include_expired
91
93
  find_matching_token(tokens, application, scopes)
92
94
  end
93
95
 
@@ -104,9 +106,7 @@ module Doorkeeper
104
106
  #
105
107
  # ActiveRecord 5.x - 6.x ignores custom ordering so we can't perform a
106
108
  # database sort by created_at, so we need to load all the matching records,
107
- # sort them and find latest one. Probably it would be better to rewrite this
108
- # query using Time math if possible, but we n eed to consider ORM and
109
- # different databases support.
109
+ # sort them and find latest one.
110
110
  #
111
111
  # @param relation [ActiveRecord::Relation]
112
112
  # Access tokens relation
@@ -181,7 +181,7 @@ module Doorkeeper
181
181
  #
182
182
  def find_or_create_for(application:, resource_owner:, scopes:, **token_attributes)
183
183
  if Doorkeeper.config.reuse_access_token
184
- access_token = matching_token_for(application, resource_owner, scopes)
184
+ access_token = matching_token_for(application, resource_owner, scopes, include_expired: false)
185
185
 
186
186
  return access_token if access_token&.reusable?
187
187
  end
@@ -213,7 +213,7 @@ module Doorkeeper
213
213
  # @return [Doorkeeper::AccessToken] new access token
214
214
  #
215
215
  def create_for(application:, resource_owner:, scopes:, **token_attributes)
216
- token_attributes[:application_id] = application&.id
216
+ token_attributes[:application] = application
217
217
  token_attributes[:scopes] = scopes.to_s
218
218
 
219
219
  if Doorkeeper.config.polymorphic_resource_owner?
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doorkeeper
4
+ module Models
5
+ module ExpirationTimeSqlMath
6
+ extend ::ActiveSupport::Concern
7
+
8
+ class ExpirationTimeSqlGenerator
9
+ attr_reader :model
10
+
11
+ delegate :table_name, to: :@model
12
+
13
+ def initialize(model)
14
+ @model = model
15
+ end
16
+
17
+ def generate_sql
18
+ raise "`generate_sql` should be overridden for a #{self.class.name}!"
19
+ end
20
+ end
21
+
22
+ class MySqlExpirationTimeSqlGenerator < ExpirationTimeSqlGenerator
23
+ def generate_sql
24
+ Arel.sql("DATE_ADD(#{table_name}.created_at, INTERVAL #{table_name}.expires_in SECOND)")
25
+ end
26
+ end
27
+
28
+ class SqlLiteExpirationTimeSqlGenerator < ExpirationTimeSqlGenerator
29
+ def generate_sql
30
+ Arel.sql("DATETIME(#{table_name}.created_at, '+' || #{table_name}.expires_in || ' SECONDS')")
31
+ end
32
+ end
33
+
34
+ class SqlServerExpirationTimeSqlGenerator < ExpirationTimeSqlGenerator
35
+ def generate_sql
36
+ Arel.sql("DATEADD(second, #{table_name}.expires_in, #{table_name}.created_at) AT TIME ZONE 'UTC'")
37
+ end
38
+ end
39
+
40
+ class OracleExpirationTimeSqlGenerator < ExpirationTimeSqlGenerator
41
+ def generate_sql
42
+ Arel.sql("#{table_name}.created_at + INTERVAL to_char(#{table_name}.expires_in) second")
43
+ end
44
+ end
45
+
46
+ class PostgresExpirationTimeSqlGenerator < ExpirationTimeSqlGenerator
47
+ def generate_sql
48
+ Arel.sql("#{table_name}.created_at + #{table_name}.expires_in * INTERVAL '1 SECOND'")
49
+ end
50
+ end
51
+
52
+ ADAPTERS_MAPPING = {
53
+ "sqlite" => SqlLiteExpirationTimeSqlGenerator,
54
+ "sqlite3" => SqlLiteExpirationTimeSqlGenerator,
55
+ "postgis" => PostgresExpirationTimeSqlGenerator,
56
+ "postgresql" => PostgresExpirationTimeSqlGenerator,
57
+ "mysql" => MySqlExpirationTimeSqlGenerator,
58
+ "mysql2" => MySqlExpirationTimeSqlGenerator,
59
+ "trilogy" => MySqlExpirationTimeSqlGenerator,
60
+ "sqlserver" => SqlServerExpirationTimeSqlGenerator,
61
+ "oracleenhanced" => OracleExpirationTimeSqlGenerator,
62
+ }.freeze
63
+
64
+ module ClassMethods
65
+ def supports_expiration_time_math?
66
+ ADAPTERS_MAPPING.key?(adapter_name.downcase) ||
67
+ respond_to?(:custom_expiration_time_sql)
68
+ end
69
+
70
+ def expiration_time_sql
71
+ if respond_to?(:custom_expiration_time_sql)
72
+ custom_expiration_time_sql
73
+ else
74
+ expiration_time_sql_expression
75
+ end
76
+ end
77
+
78
+ def expiration_time_sql_expression
79
+ ADAPTERS_MAPPING.fetch(adapter_name.downcase).new(self).generate_sql
80
+ end
81
+
82
+ def adapter_name
83
+ ActiveRecord::Base.connection.adapter_name
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doorkeeper
4
+ module Models
5
+ module PolymorphicResourceOwner
6
+ module ForAccessGrant
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ if Doorkeeper.config.polymorphic_resource_owner?
11
+ belongs_to :resource_owner, polymorphic: true, optional: false
12
+ else
13
+ validates :resource_owner_id, presence: true
14
+ end
15
+ end
16
+ end
17
+
18
+ module ForAccessToken
19
+ extend ActiveSupport::Concern
20
+
21
+ included do
22
+ if Doorkeeper.config.polymorphic_resource_owner?
23
+ belongs_to :resource_owner, polymorphic: true, optional: true
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -60,7 +60,7 @@ module Doorkeeper
60
60
  )
61
61
 
62
62
  @token = Doorkeeper.config.access_token_model.find_or_create_for(
63
- application: pre_auth.client,
63
+ application: application,
64
64
  resource_owner: resource_owner,
65
65
  scopes: pre_auth.scopes,
66
66
  expires_in: self.class.access_token_expires_in(Doorkeeper.config, context),
@@ -68,6 +68,12 @@ module Doorkeeper
68
68
  )
69
69
  end
70
70
 
71
+ def application
72
+ return unless pre_auth.client
73
+
74
+ pre_auth.client.is_a?(Doorkeeper.config.application_model) ? pre_auth.client : pre_auth.client.application
75
+ end
76
+
71
77
  def oob_redirect
72
78
  {
73
79
  controller: controller,
@@ -29,7 +29,7 @@ module Doorkeeper
29
29
  def find_or_create_access_token(client, resource_owner, scopes, server)
30
30
  context = Authorization::Token.build_context(client, grant_type, scopes, resource_owner)
31
31
  @access_token = server_config.access_token_model.find_or_create_for(
32
- application: client,
32
+ application: client.is_a?(server_config.application_model) ? client : client&.application,
33
33
  resource_owner: resource_owner,
34
34
  scopes: scopes,
35
35
  expires_in: Authorization::Token.access_token_expires_in(server, context),
@@ -8,13 +8,14 @@ module Doorkeeper
8
8
  existing_token = nil
9
9
 
10
10
  if lookup_existing_token?
11
- existing_token = find_existing_token_for(client, scopes)
11
+ existing_token = find_active_existing_token_for(client, scopes)
12
12
  return existing_token if server_config.reuse_access_token && existing_token&.reusable?
13
13
  end
14
14
 
15
15
  with_revocation(existing_token: existing_token) do
16
- server_config.access_token_model.find_or_create_for(
17
- application: client,
16
+ application = client.is_a?(server_config.application_model) ? client : client&.application
17
+ server_config.access_token_model.create_for(
18
+ application: application,
18
19
  resource_owner: nil,
19
20
  scopes: scopes,
20
21
  **attributes,
@@ -43,8 +44,8 @@ module Doorkeeper
43
44
  server_config.revoke_previous_client_credentials_token?
44
45
  end
45
46
 
46
- def find_existing_token_for(client, scopes)
47
- server_config.access_token_model.matching_token_for(client, nil, scopes)
47
+ def find_active_existing_token_for(client, scopes)
48
+ server_config.access_token_model.matching_token_for(client, nil, scopes, include_expired: false)
48
49
  end
49
50
 
50
51
  def server_config
@@ -35,13 +35,12 @@ module Doorkeeper
35
35
  end
36
36
 
37
37
  def validate_scopes
38
- return true if @request.scopes.blank?
39
-
40
38
  application_scopes = if @client.present?
41
39
  @client.application.scopes
42
40
  else
43
41
  ""
44
42
  end
43
+ return true if @request.scopes.blank? && application_scopes.blank?
45
44
 
46
45
  ScopeChecker.valid?(
47
46
  scope_str: @request.scopes.to_s,
@@ -61,9 +61,9 @@ module Doorkeeper
61
61
  end
62
62
 
63
63
  def self.valid_scheme?(uri)
64
- return false if uri.scheme.nil?
64
+ return false if uri.scheme.blank?
65
65
 
66
- %w[localhost].include?(uri.scheme) == false
66
+ %w[localhost].exclude?(uri.scheme)
67
67
  end
68
68
 
69
69
  def self.hypertext_scheme?(uri)
@@ -71,7 +71,7 @@ module Doorkeeper
71
71
  end
72
72
 
73
73
  def self.iff_host?(uri)
74
- !(hypertext_scheme?(uri) && uri.host.nil?)
74
+ !(hypertext_scheme?(uri) && uri.host.blank?)
75
75
  end
76
76
 
77
77
  def self.oob_uri?(uri)
@@ -134,7 +134,7 @@ module Doorkeeper
134
134
  # Since resource servers using token introspection rely on the
135
135
  # authorization server to determine the state of a token, the
136
136
  # authorization server MUST perform all applicable checks against a
137
- # token's state. For instance, these tests include the following:
137
+ # token's state. For instance, these tests include the following:
138
138
  #
139
139
  # o If the token can expire, the authorization server MUST determine
140
140
  # whether or not the token has expired.
@@ -14,12 +14,6 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
14
14
  optional: true,
15
15
  inverse_of: :access_grants
16
16
 
17
- if Doorkeeper.config.polymorphic_resource_owner?
18
- belongs_to :resource_owner, polymorphic: true, optional: false
19
- else
20
- validates :resource_owner_id, presence: true
21
- end
22
-
23
17
  validates :application_id,
24
18
  :token,
25
19
  :expires_in,
@@ -14,10 +14,6 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
14
14
  inverse_of: :access_tokens,
15
15
  optional: true
16
16
 
17
- if Doorkeeper.config.polymorphic_resource_owner?
18
- belongs_to :resource_owner, polymorphic: true, optional: true
19
- end
20
-
21
17
  validates :token, presence: true, uniqueness: { case_sensitive: true }
22
18
  validates :refresh_token, uniqueness: { case_sensitive: true }, if: :use_refresh_token?
23
19
 
@@ -48,6 +44,27 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
48
44
  column_names.include?("previous_refresh_token")
49
45
  end
50
46
 
47
+ # Returns non-expired and non-revoked access tokens
48
+ def not_expired
49
+ relation = where(revoked_at: nil)
50
+
51
+ if supports_expiration_time_math?
52
+ # have not reached the expiration time or it never expires
53
+ relation.where("#{expiration_time_sql} > ?", Time.now.utc).or(
54
+ relation.where(expires_in: nil)
55
+ )
56
+ else
57
+ ::Kernel.warn <<~WARNING.squish
58
+ [DOORKEEPER] Doorkeeper doesn't support expiration time math for your database adapter (#{adapter_name}).
59
+ Please add a class method `custom_expiration_time_sql` for your AccessToken class/mixin to provide a custom
60
+ SQL expression to calculate access token expiration time. See lib/doorkeeper/orm/active_record/mixins/access_token.rb
61
+ for more details.
62
+ WARNING
63
+
64
+ relation
65
+ end
66
+ end
67
+
51
68
  private
52
69
 
53
70
  def compute_doorkeeper_table_name
@@ -44,7 +44,7 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
44
44
  # @return [String] new transformed secret value
45
45
  #
46
46
  def renew_secret
47
- @raw_secret = Doorkeeper::OAuth::Helpers::UniqueToken.generate
47
+ @raw_secret = secret_generator.generate
48
48
  secret_strategy.store_secret(self, :secret, @raw_secret)
49
49
  end
50
50
 
@@ -102,6 +102,17 @@ module Doorkeeper::Orm::ActiveRecord::Mixins
102
102
 
103
103
  private
104
104
 
105
+ def secret_generator
106
+ generator_name = Doorkeeper.config.application_secret_generator
107
+ generator = generator_name.constantize
108
+
109
+ return generator if generator.respond_to?(:generate)
110
+
111
+ raise Errors::UnableToGenerateToken, "#{generator} does not respond to `.generate`."
112
+ rescue NameError
113
+ raise Errors::TokenGeneratorNotFound, "#{generator_name} not found"
114
+ end
115
+
105
116
  def generate_uid
106
117
  self.uid = Doorkeeper::OAuth::Helpers::UniqueToken.generate if uid.blank?
107
118
  end
@@ -45,11 +45,11 @@ module Doorkeeper
45
45
  end
46
46
 
47
47
  def unspecified_host?(uri)
48
- uri.is_a?(URI::HTTP) && uri.host.nil?
48
+ uri.is_a?(URI::HTTP) && uri.host.blank?
49
49
  end
50
50
 
51
51
  def relative_uri?(uri)
52
- uri.scheme.nil? && uri.host.nil?
52
+ uri.scheme.nil? && uri.host.blank?
53
53
  end
54
54
 
55
55
  def invalid_ssl_uri?(uri)
@@ -15,7 +15,8 @@ module Doorkeeper
15
15
  def clean_revoked
16
16
  table = @base_scope.arel_table
17
17
 
18
- @base_scope.where.not(revoked_at: nil)
18
+ @base_scope
19
+ .where.not(revoked_at: nil)
19
20
  .where(table[:revoked_at].lt(Time.current))
20
21
  .in_batches(&:delete_all)
21
22
  end
@@ -24,7 +25,9 @@ module Doorkeeper
24
25
  def clean_expired(ttl)
25
26
  table = @base_scope.arel_table
26
27
 
27
- @base_scope.where(table[:created_at].lt(Time.current - ttl))
28
+ @base_scope
29
+ .where.not(expires_in: nil)
30
+ .where(table[:created_at].lt(Time.current - ttl))
28
31
  .in_batches(&:delete_all)
29
32
  end
30
33
  end
@@ -1,51 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/lazy_load_hooks"
4
-
5
3
  module Doorkeeper
4
+ autoload :AccessGrant, "doorkeeper/orm/active_record/access_grant"
5
+ autoload :AccessToken, "doorkeeper/orm/active_record/access_token"
6
+ autoload :Application, "doorkeeper/orm/active_record/application"
7
+ autoload :RedirectUriValidator, "doorkeeper/orm/active_record/redirect_uri_validator"
8
+
9
+ module Models
10
+ autoload :Ownership, "doorkeeper/models/concerns/ownership"
11
+ end
12
+
13
+ # ActiveRecord ORM for Doorkeeper entity models.
14
+ # Consists of three main OAuth entities:
15
+ # * Access Token
16
+ # * Access Grant
17
+ # * Application (client)
18
+ #
19
+ # Do a lazy loading of all the required and configured stuff.
20
+ #
6
21
  module Orm
7
- # ActiveRecord ORM for Doorkeeper entity models.
8
- # Consists of three main OAuth entities:
9
- # * Access Token
10
- # * Access Grant
11
- # * Application (client)
12
- #
13
- # Do a lazy loading of all the required and configured stuff.
14
- #
15
22
  module ActiveRecord
16
- def self.initialize_models!
17
- lazy_load do
18
- require "doorkeeper/orm/active_record/stale_records_cleaner"
19
- require "doorkeeper/orm/active_record/access_grant"
20
- require "doorkeeper/orm/active_record/access_token"
21
- require "doorkeeper/orm/active_record/application"
23
+ autoload :StaleRecordsCleaner, "doorkeeper/orm/active_record/stale_records_cleaner"
22
24
 
23
- if (options = Doorkeeper.config.active_record_options[:establish_connection])
24
- Doorkeeper::Orm::ActiveRecord.models.each do |model|
25
- model.establish_connection(options)
26
- end
27
- end
28
- end
25
+ module Mixins
26
+ autoload :AccessGrant, "doorkeeper/orm/active_record/mixins/access_grant"
27
+ autoload :AccessToken, "doorkeeper/orm/active_record/mixins/access_token"
28
+ autoload :Application, "doorkeeper/orm/active_record/mixins/application"
29
29
  end
30
30
 
31
- def self.initialize_application_owner!
32
- lazy_load do
33
- require "doorkeeper/models/concerns/ownership"
34
-
35
- Doorkeeper.config.application_model.include(Doorkeeper::Models::Ownership)
36
- end
31
+ def self.run_hooks
32
+ initialize_configured_associations
37
33
  end
38
34
 
39
- def self.lazy_load(&block)
40
- ActiveSupport.on_load(:active_record, {}, &block)
41
- end
35
+ def self.initialize_configured_associations
36
+ if Doorkeeper.config.enable_application_owner?
37
+ Doorkeeper.config.application_model.include ::Doorkeeper::Models::Ownership
38
+ end
42
39
 
43
- def self.models
44
- [
45
- Doorkeeper.config.access_grant_model,
46
- Doorkeeper.config.access_token_model,
47
- Doorkeeper.config.application_model,
48
- ]
40
+ Doorkeeper.config.access_grant_model.include ::Doorkeeper::Models::PolymorphicResourceOwner::ForAccessGrant
41
+ Doorkeeper.config.access_token_model.include ::Doorkeeper::Models::PolymorphicResourceOwner::ForAccessToken
49
42
  end
50
43
  end
51
44
  end
@@ -36,7 +36,7 @@ module Doorkeeper
36
36
  map_route(:authorizations, :authorization_routes)
37
37
  map_route(:tokens, :token_routes)
38
38
  map_route(:tokens, :revoke_routes)
39
- map_route(:tokens, :introspect_routes) unless Doorkeeper.config.allow_token_introspection.is_a?(FalseClass)
39
+ map_route(:tokens, :introspect_routes) if introspection_routes?
40
40
  map_route(:applications, :application_routes)
41
41
  map_route(:authorized_applications, :authorized_applications_routes)
42
42
  map_route(:token_info, :token_info_routes)
@@ -53,8 +53,8 @@ module Doorkeeper
53
53
  as: mapping[:as],
54
54
  controller: mapping[:controllers],
55
55
  ) do
56
- routes.get "/native", action: :show, on: :member
57
- routes.get "/", action: :new, on: :member
56
+ routes.get native_authorization_code_route, action: :show, on: :member
57
+ routes.get '/', action: :new, on: :member
58
58
  end
59
59
  end
60
60
 
@@ -96,6 +96,15 @@ module Doorkeeper
96
96
  only: %i[index destroy],
97
97
  controller: mapping[:controllers]
98
98
  end
99
+
100
+ def native_authorization_code_route
101
+ Doorkeeper.configuration.native_authorization_code_route
102
+ end
103
+
104
+ def introspection_routes?
105
+ Doorkeeper.configured? &&
106
+ !Doorkeeper.config.allow_token_introspection.is_a?(FalseClass)
107
+ end
99
108
  end
100
109
  end
101
110
  end
@@ -2,10 +2,5 @@
2
2
 
3
3
  namespace :doorkeeper do
4
4
  task setup: :environment do
5
- # Dirty hack to manually initialize AR because of lazy auto-loading,
6
- # in other case we'll see NameError: uninitialized constant Doorkeeper::AccessToken
7
- if Doorkeeper.config.orm == :active_record && defined?(::ActiveRecord::Base)
8
- Object.const_get("::ActiveRecord::Base")
9
- end
10
5
  end
11
6
  end
@@ -4,7 +4,7 @@ module Doorkeeper
4
4
  module VERSION
5
5
  # Semantic versioning
6
6
  MAJOR = 5
7
- MINOR = 5
7
+ MINOR = 6
8
8
  TINY = 4
9
9
  PRE = nil
10
10
 
data/lib/doorkeeper.rb CHANGED
@@ -88,7 +88,9 @@ module Doorkeeper
88
88
  module Models
89
89
  autoload :Accessible, "doorkeeper/models/concerns/accessible"
90
90
  autoload :Expirable, "doorkeeper/models/concerns/expirable"
91
+ autoload :ExpirationTimeSqlMath, "doorkeeper/models/concerns/expiration_time_sql_math"
91
92
  autoload :Orderable, "doorkeeper/models/concerns/orderable"
93
+ autoload :PolymorphicResourceOwner, "doorkeeper/models/concerns/polymorphic_resource_owner"
92
94
  autoload :Scopes, "doorkeeper/models/concerns/scopes"
93
95
  autoload :Reusable, "doorkeeper/models/concerns/reusable"
94
96
  autoload :ResourceOwnerable, "doorkeeper/models/concerns/resource_ownerable"
@@ -112,11 +114,77 @@ module Doorkeeper
112
114
  autoload :BCrypt, "doorkeeper/secret_storing/bcrypt"
113
115
  end
114
116
 
115
- def self.authenticate(request, methods = Doorkeeper.config.access_token_methods)
116
- OAuth::Token.authenticate(request, *methods)
117
- end
117
+ class << self
118
+ attr_reader :orm_adapter
119
+
120
+ def configure(&block)
121
+ @config = Config::Builder.new(&block).build
122
+ setup
123
+ @config
124
+ end
125
+
126
+ # @return [Doorkeeper::Config] configuration instance
127
+ #
128
+ def configuration
129
+ @config || configure
130
+ end
131
+
132
+ def configured?
133
+ !@config.nil?
134
+ end
135
+
136
+ alias config configuration
137
+
138
+ def setup
139
+ setup_orm_adapter
140
+
141
+ # Deprecated, will be removed soon
142
+ unless configuration.orm == :active_record
143
+ setup_orm_models
144
+ setup_application_owner
145
+ end
146
+ end
147
+
148
+ def setup_orm_adapter
149
+ @orm_adapter = "doorkeeper/orm/#{configuration.orm}".classify.constantize
150
+ rescue NameError => e
151
+ raise e, "ORM adapter not found (#{configuration.orm})", <<-ERROR_MSG.strip_heredoc
152
+ [DOORKEEPER] ORM adapter not found (#{configuration.orm}), or there was an error
153
+ trying to load it.
118
154
 
119
- def self.gem_version
120
- ::Gem::Version.new(::Doorkeeper::VERSION::STRING)
155
+ You probably need to add the related gem for this adapter to work with
156
+ doorkeeper.
157
+ ERROR_MSG
158
+ end
159
+
160
+ def run_orm_hooks
161
+ config.clear_cache!
162
+
163
+ if @orm_adapter.respond_to?(:run_hooks)
164
+ @orm_adapter.run_hooks
165
+ else
166
+ ::Kernel.warn <<~MSG.strip_heredoc
167
+ [DOORKEEPER] ORM "#{configuration.orm}" should move all it's setup logic under `#run_hooks` method for
168
+ the #{@orm_adapter.name}. Later versions of Doorkeeper will no longer support `setup_orm_models` and
169
+ `setup_application_owner` API.
170
+ MSG
171
+ end
172
+ end
173
+
174
+ def setup_orm_models
175
+ @orm_adapter.initialize_models!
176
+ end
177
+
178
+ def setup_application_owner
179
+ @orm_adapter.initialize_application_owner!
180
+ end
181
+
182
+ def authenticate(request, methods = Doorkeeper.config.access_token_methods)
183
+ OAuth::Token.authenticate(request, *methods)
184
+ end
185
+
186
+ def gem_version
187
+ ::Gem::Version.new(::Doorkeeper::VERSION::STRING)
188
+ end
121
189
  end
122
190
  end
@@ -126,9 +126,10 @@ Doorkeeper.configure do
126
126
 
127
127
  # Reuse access token for the same resource owner within an application (disabled by default).
128
128
  #
129
- # This option protects your application from creating new tokens before old valid one becomes
130
- # expired so your database doesn't bloat. Keep in mind that when this option is `on` Doorkeeper
131
- # doesn't updates existing token expiration time, it will create a new token instead.
129
+ # This option protects your application from creating new tokens before old **valid** one becomes
130
+ # expired so your database doesn't bloat. Keep in mind that when this option is enabled Doorkeeper
131
+ # doesn't update existing token expiration time, it will create a new token instead if no active matching
132
+ # token found for the application, resources owner and/or set of scopes.
132
133
  # Rationale: https://github.com/doorkeeper-gem/doorkeeper/issues/383
133
134
  #
134
135
  # You can not enable this option together with +hash_token_secrets+.
@@ -24,9 +24,9 @@ class CreateDoorkeeperTables < ActiveRecord::Migration<%= migration_version %>
24
24
  t.string :token, null: false
25
25
  t.integer :expires_in, null: false
26
26
  t.text :redirect_uri, null: false
27
+ t.string :scopes, null: false, default: ''
27
28
  t.datetime :created_at, null: false
28
29
  t.datetime :revoked_at
29
- t.string :scopes, null: false, default: ''
30
30
  end
31
31
 
32
32
  add_index :oauth_access_grants, :token, unique: true
@@ -53,9 +53,9 @@ class CreateDoorkeeperTables < ActiveRecord::Migration<%= migration_version %>
53
53
 
54
54
  t.string :refresh_token
55
55
  t.integer :expires_in
56
- t.datetime :revoked_at
57
- t.datetime :created_at, null: false
58
56
  t.string :scopes
57
+ t.datetime :created_at, null: false
58
+ t.datetime :revoked_at
59
59
 
60
60
  # The authorization server MAY issue a new refresh token, in which case
61
61
  # *the client MUST discard the old refresh token* and replace it with the
@@ -74,7 +74,17 @@ class CreateDoorkeeperTables < ActiveRecord::Migration<%= migration_version %>
74
74
  end
75
75
 
76
76
  add_index :oauth_access_tokens, :token, unique: true
77
- add_index :oauth_access_tokens, :refresh_token, unique: true
77
+
78
+ # See https://github.com/doorkeeper-gem/doorkeeper/issues/1592
79
+ if ActiveRecord::Base.connection.adapter_name == "SQLServer"
80
+ execute <<~SQL.squish
81
+ CREATE UNIQUE NONCLUSTERED INDEX index_oauth_access_tokens_on_refresh_token ON oauth_access_tokens(refresh_token)
82
+ WHERE refresh_token IS NOT NULL
83
+ SQL
84
+ else
85
+ add_index :oauth_access_tokens, :refresh_token, unique: true
86
+ end
87
+
78
88
  add_foreign_key(
79
89
  :oauth_access_tokens,
80
90
  :oauth_applications,
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.5.4
4
+ version: 5.6.4
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: 2021-10-05 00:00:00.000000000 Z
14
+ date: 2023-01-31 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: railties
@@ -56,7 +56,7 @@ dependencies:
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  - !ruby/object:Gem::Dependency
59
- name: coveralls
59
+ name: coveralls_reborn
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - ">="
@@ -69,20 +69,6 @@ dependencies:
69
69
  - - ">="
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
- - !ruby/object:Gem::Dependency
73
- name: danger
74
- requirement: !ruby/object:Gem::Requirement
75
- requirements:
76
- - - "~>"
77
- - !ruby/object:Gem::Version
78
- version: '8.0'
79
- type: :development
80
- prerelease: false
81
- version_requirements: !ruby/object:Gem::Requirement
82
- requirements:
83
- - - "~>"
84
- - !ruby/object:Gem::Version
85
- version: '8.0'
86
72
  - !ruby/object:Gem::Dependency
87
73
  name: database_cleaner
88
74
  requirement: !ruby/object:Gem::Requirement
@@ -167,6 +153,20 @@ dependencies:
167
153
  - - ">="
168
154
  - !ruby/object:Gem::Version
169
155
  version: '0'
156
+ - !ruby/object:Gem::Dependency
157
+ name: timecop
158
+ requirement: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ type: :development
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
170
  description: Doorkeeper is an OAuth 2 provider for Rails and Grape.
171
171
  email:
172
172
  - bulaj.nikita@gmail.com
@@ -221,8 +221,10 @@ files:
221
221
  - lib/doorkeeper/models/application_mixin.rb
222
222
  - lib/doorkeeper/models/concerns/accessible.rb
223
223
  - lib/doorkeeper/models/concerns/expirable.rb
224
+ - lib/doorkeeper/models/concerns/expiration_time_sql_math.rb
224
225
  - lib/doorkeeper/models/concerns/orderable.rb
225
226
  - lib/doorkeeper/models/concerns/ownership.rb
227
+ - lib/doorkeeper/models/concerns/polymorphic_resource_owner.rb
226
228
  - lib/doorkeeper/models/concerns/resource_ownerable.rb
227
229
  - lib/doorkeeper/models/concerns/reusable.rb
228
230
  - lib/doorkeeper/models/concerns/revocable.rb
@@ -337,14 +339,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
337
339
  requirements:
338
340
  - - ">="
339
341
  - !ruby/object:Gem::Version
340
- version: '2.5'
342
+ version: '2.7'
341
343
  required_rubygems_version: !ruby/object:Gem::Requirement
342
344
  requirements:
343
345
  - - ">="
344
346
  - !ruby/object:Gem::Version
345
347
  version: '0'
346
348
  requirements: []
347
- rubygems_version: 3.1.2
349
+ rubygems_version: 3.1.6
348
350
  signing_key:
349
351
  specification_version: 4
350
352
  summary: OAuth 2 provider for Rails and Grape