doorkeeper 5.2.0 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +2 -2
  3. data/CHANGELOG.md +40 -2
  4. data/Gemfile +2 -2
  5. data/app/controllers/doorkeeper/application_controller.rb +2 -2
  6. data/app/controllers/doorkeeper/application_metal_controller.rb +2 -2
  7. data/app/controllers/doorkeeper/applications_controller.rb +0 -1
  8. data/app/controllers/doorkeeper/authorizations_controller.rb +2 -2
  9. data/app/controllers/doorkeeper/authorized_applications_controller.rb +2 -2
  10. data/config/locales/en.yml +1 -1
  11. data/gemfiles/rails_5_0.gemfile +2 -2
  12. data/gemfiles/rails_5_1.gemfile +2 -2
  13. data/gemfiles/rails_5_2.gemfile +2 -2
  14. data/gemfiles/rails_6_0.gemfile +2 -2
  15. data/gemfiles/rails_master.gemfile +2 -2
  16. data/lib/doorkeeper/config.rb +71 -38
  17. data/lib/doorkeeper/grape/helpers.rb +1 -1
  18. data/lib/doorkeeper/helpers/controller.rb +12 -8
  19. data/lib/doorkeeper/models/access_grant_mixin.rb +7 -6
  20. data/lib/doorkeeper/models/access_token_mixin.rb +56 -18
  21. data/lib/doorkeeper/models/application_mixin.rb +3 -3
  22. data/lib/doorkeeper/models/concerns/ownership.rb +1 -1
  23. data/lib/doorkeeper/models/concerns/reusable.rb +1 -1
  24. data/lib/doorkeeper/models/concerns/revocable.rb +0 -27
  25. data/lib/doorkeeper/oauth/authorization/code.rb +4 -4
  26. data/lib/doorkeeper/oauth/authorization/token.rb +9 -6
  27. data/lib/doorkeeper/oauth/authorization_code_request.rb +13 -6
  28. data/lib/doorkeeper/oauth/base_request.rb +8 -4
  29. data/lib/doorkeeper/oauth/client.rb +7 -8
  30. data/lib/doorkeeper/oauth/client_credentials/creator.rb +16 -9
  31. data/lib/doorkeeper/oauth/client_credentials/issuer.rb +7 -7
  32. data/lib/doorkeeper/oauth/client_credentials/{validation.rb → validator.rb} +4 -4
  33. data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -1
  34. data/lib/doorkeeper/oauth/code_response.rb +2 -2
  35. data/lib/doorkeeper/oauth/error.rb +1 -1
  36. data/lib/doorkeeper/oauth/error_response.rb +5 -5
  37. data/lib/doorkeeper/oauth/helpers/scope_checker.rb +7 -5
  38. data/lib/doorkeeper/oauth/helpers/unique_token.rb +8 -5
  39. data/lib/doorkeeper/oauth/helpers/uri_checker.rb +1 -1
  40. data/lib/doorkeeper/oauth/invalid_request_response.rb +3 -3
  41. data/lib/doorkeeper/oauth/invalid_token_response.rb +5 -2
  42. data/lib/doorkeeper/oauth/password_access_token_request.rb +3 -3
  43. data/lib/doorkeeper/oauth/pre_authorization.rb +12 -7
  44. data/lib/doorkeeper/oauth/refresh_token_request.rb +5 -5
  45. data/lib/doorkeeper/oauth/token.rb +2 -2
  46. data/lib/doorkeeper/oauth/token_introspection.rb +6 -6
  47. data/lib/doorkeeper/orm/active_record/access_grant.rb +4 -43
  48. data/lib/doorkeeper/orm/active_record/access_token.rb +4 -35
  49. data/lib/doorkeeper/orm/active_record/application.rb +5 -89
  50. data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +53 -0
  51. data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +47 -0
  52. data/lib/doorkeeper/orm/active_record/mixins/application.rb +128 -0
  53. data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +3 -3
  54. data/lib/doorkeeper/orm/active_record.rb +3 -4
  55. data/lib/doorkeeper/rails/helpers.rb +4 -4
  56. data/lib/doorkeeper/rails/routes.rb +5 -7
  57. data/lib/doorkeeper/rake/db.rake +3 -3
  58. data/lib/doorkeeper/request/authorization_code.rb +3 -3
  59. data/lib/doorkeeper/request/client_credentials.rb +2 -2
  60. data/lib/doorkeeper/request/password.rb +2 -2
  61. data/lib/doorkeeper/request/refresh_token.rb +3 -3
  62. data/lib/doorkeeper/request.rb +1 -1
  63. data/lib/doorkeeper/server.rb +1 -1
  64. data/lib/doorkeeper/stale_records_cleaner.rb +1 -1
  65. data/lib/doorkeeper/version.rb +1 -1
  66. data/lib/doorkeeper.rb +2 -3
  67. data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
  68. data/lib/generators/doorkeeper/confidential_applications_generator.rb +1 -1
  69. data/lib/generators/doorkeeper/migration_generator.rb +1 -1
  70. data/lib/generators/doorkeeper/pkce_generator.rb +1 -1
  71. data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +2 -2
  72. data/lib/generators/doorkeeper/templates/initializer.rb +39 -0
  73. data/spec/controllers/application_metal_controller_spec.rb +1 -1
  74. data/spec/controllers/applications_controller_spec.rb +3 -2
  75. data/spec/controllers/authorizations_controller_spec.rb +20 -18
  76. data/spec/controllers/protected_resources_controller_spec.rb +25 -17
  77. data/spec/controllers/token_info_controller_spec.rb +1 -1
  78. data/spec/controllers/tokens_controller_spec.rb +1 -1
  79. data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +3 -3
  80. data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +1 -1
  81. data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +1 -1
  82. data/spec/generators/install_generator_spec.rb +1 -1
  83. data/spec/generators/previous_refresh_token_generator_spec.rb +2 -2
  84. data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
  85. data/spec/lib/config_spec.rb +62 -7
  86. data/spec/lib/doorkeeper_spec.rb +1 -1
  87. data/spec/lib/models/revocable_spec.rb +3 -3
  88. data/spec/lib/oauth/authorization_code_request_spec.rb +127 -123
  89. data/spec/lib/oauth/base_request_spec.rb +160 -158
  90. data/spec/lib/oauth/base_response_spec.rb +27 -29
  91. data/spec/lib/oauth/client/credentials_spec.rb +1 -1
  92. data/spec/lib/oauth/client_credentials/creator_spec.rb +42 -5
  93. data/spec/lib/oauth/client_credentials/issuer_spec.rb +12 -12
  94. data/spec/lib/oauth/client_credentials/validation_spec.rb +4 -4
  95. data/spec/lib/oauth/client_credentials_integration_spec.rb +16 -18
  96. data/spec/lib/oauth/client_credentials_request_spec.rb +78 -80
  97. data/spec/lib/oauth/client_spec.rb +26 -26
  98. data/spec/lib/oauth/code_request_spec.rb +34 -34
  99. data/spec/lib/oauth/code_response_spec.rb +21 -25
  100. data/spec/lib/oauth/error_response_spec.rb +42 -44
  101. data/spec/lib/oauth/error_spec.rb +12 -14
  102. data/spec/lib/oauth/forbidden_token_response_spec.rb +11 -13
  103. data/spec/lib/oauth/helpers/scope_checker_spec.rb +30 -18
  104. data/spec/lib/oauth/invalid_request_response_spec.rb +48 -50
  105. data/spec/lib/oauth/invalid_token_response_spec.rb +32 -34
  106. data/spec/lib/oauth/password_access_token_request_spec.rb +145 -147
  107. data/spec/lib/oauth/pre_authorization_spec.rb +159 -161
  108. data/spec/lib/oauth/refresh_token_request_spec.rb +138 -139
  109. data/spec/lib/oauth/scopes_spec.rb +104 -106
  110. data/spec/lib/oauth/token_request_spec.rb +115 -111
  111. data/spec/lib/oauth/token_response_spec.rb +71 -73
  112. data/spec/lib/oauth/token_spec.rb +121 -123
  113. data/spec/models/doorkeeper/access_grant_spec.rb +21 -4
  114. data/spec/models/doorkeeper/access_token_spec.rb +42 -11
  115. data/spec/models/doorkeeper/application_spec.rb +114 -77
  116. data/spec/requests/applications/applications_request_spec.rb +1 -1
  117. data/spec/requests/endpoints/authorization_spec.rb +5 -3
  118. data/spec/requests/flows/authorization_code_spec.rb +34 -22
  119. data/spec/requests/flows/client_credentials_spec.rb +1 -1
  120. data/spec/requests/flows/password_spec.rb +32 -12
  121. data/spec/requests/flows/refresh_token_spec.rb +19 -19
  122. data/spec/requests/flows/revoke_token_spec.rb +18 -12
  123. data/spec/spec_helper.rb +1 -4
  124. data/spec/support/shared/controllers_shared_context.rb +33 -23
  125. data/spec/validators/redirect_uri_validator_spec.rb +1 -1
  126. metadata +6 -5
  127. data/spec/support/http_method_shim.rb +0 -29
@@ -16,14 +16,13 @@ module Doorkeeper
16
16
  def self.initialize_models!
17
17
  lazy_load do
18
18
  require "doorkeeper/orm/active_record/stale_records_cleaner"
19
- require "doorkeeper/orm/active_record/redirect_uri_validator"
20
19
  require "doorkeeper/orm/active_record/access_grant"
21
20
  require "doorkeeper/orm/active_record/access_token"
22
21
  require "doorkeeper/orm/active_record/application"
23
22
 
24
- if Doorkeeper.configuration.active_record_options[:establish_connection]
23
+ if Doorkeeper.config.active_record_options[:establish_connection]
25
24
  Doorkeeper::Orm::ActiveRecord.models.each do |model|
26
- options = Doorkeeper.configuration.active_record_options[:establish_connection]
25
+ options = Doorkeeper.config.active_record_options[:establish_connection]
27
26
  model.establish_connection(options)
28
27
  end
29
28
  end
@@ -34,7 +33,7 @@ module Doorkeeper
34
33
  lazy_load do
35
34
  require "doorkeeper/models/concerns/ownership"
36
35
 
37
- Doorkeeper::Application.send :include, Doorkeeper::Models::Ownership
36
+ Doorkeeper.config.application_model.send :include, Doorkeeper::Models::Ownership
38
37
  end
39
38
  end
40
39
 
@@ -4,7 +4,7 @@ module Doorkeeper
4
4
  module Rails
5
5
  module Helpers
6
6
  def doorkeeper_authorize!(*scopes)
7
- @_doorkeeper_scopes = scopes.presence || Doorkeeper.configuration.default_scopes
7
+ @_doorkeeper_scopes = scopes.presence || Doorkeeper.config.default_scopes
8
8
 
9
9
  doorkeeper_render_error unless valid_doorkeeper_token?
10
10
  end
@@ -21,7 +21,7 @@ module Doorkeeper
21
21
 
22
22
  def doorkeeper_render_error
23
23
  error = doorkeeper_error
24
- error.raise_exception! if Doorkeeper.configuration.raise_on_errors?
24
+ error.raise_exception! if Doorkeeper.config.raise_on_errors?
25
25
 
26
26
  headers.merge!(error.headers.reject { |k| k == "Content-Type" })
27
27
  doorkeeper_render_error_with(error)
@@ -30,7 +30,7 @@ module Doorkeeper
30
30
  def doorkeeper_render_error_with(error)
31
31
  options = doorkeeper_render_options(error) || {}
32
32
  status = doorkeeper_status_for_error(
33
- error, options.delete(:respond_not_found_when_forbidden)
33
+ error, options.delete(:respond_not_found_when_forbidden),
34
34
  )
35
35
  if options.blank?
36
36
  head status
@@ -72,7 +72,7 @@ module Doorkeeper
72
72
  def doorkeeper_token
73
73
  @doorkeeper_token ||= OAuth::Token.authenticate(
74
74
  request,
75
- *Doorkeeper.configuration.access_token_methods
75
+ *Doorkeeper.config.access_token_methods,
76
76
  )
77
77
  end
78
78
  end
@@ -17,7 +17,7 @@ module Doorkeeper
17
17
  end
18
18
 
19
19
  def self.install!
20
- ActionDispatch::Routing::Mapper.send :include, Doorkeeper::Rails::Routes::Helper
20
+ ActionDispatch::Routing::Mapper.include Doorkeeper::Rails::Routes::Helper
21
21
  end
22
22
 
23
23
  attr_reader :routes
@@ -26,9 +26,7 @@ module Doorkeeper
26
26
  @routes = routes
27
27
  @mapping = Mapper.new.map(&block)
28
28
 
29
- if Doorkeeper.configuration.api_only
30
- @mapping.skips.push(:applications, :authorized_applications)
31
- end
29
+ @mapping.skips.push(:applications, :authorized_applications) if Doorkeeper.config.api_only
32
30
  end
33
31
 
34
32
  def generate_routes!(options)
@@ -59,7 +57,7 @@ module Doorkeeper
59
57
  path: "authorize",
60
58
  only: %i[create destroy],
61
59
  as: mapping[:as],
62
- controller: mapping[:controllers]
60
+ controller: mapping[:controllers],
63
61
  ) do
64
62
  routes.get "/native", action: :show, on: :member
65
63
  routes.get "/", action: :new, on: :member
@@ -71,7 +69,7 @@ module Doorkeeper
71
69
  :token,
72
70
  path: "token",
73
71
  only: [:create], as: mapping[:as],
74
- controller: mapping[:controllers]
72
+ controller: mapping[:controllers],
75
73
  )
76
74
  end
77
75
 
@@ -88,7 +86,7 @@ module Doorkeeper
88
86
  :token_info,
89
87
  path: "token/info",
90
88
  only: [:show], as: mapping[:as],
91
- controller: mapping[:controllers]
89
+ controller: mapping[:controllers],
92
90
  )
93
91
  end
94
92
 
@@ -19,9 +19,9 @@ namespace :doorkeeper do
19
19
 
20
20
  desc "Removes expired (TTL passed) access tokens"
21
21
  task expired_tokens: "doorkeeper:setup" do
22
- expirable_tokens = Doorkeeper::AccessToken.where(refresh_token: nil)
22
+ expirable_tokens = Doorkeeper.config.access_token_model.where(refresh_token: nil)
23
23
  cleaner = Doorkeeper::StaleRecordsCleaner.new(expirable_tokens)
24
- cleaner.clean_expired(Doorkeeper.configuration.access_token_expires_in)
24
+ cleaner.clean_expired(Doorkeeper.config.access_token_expires_in)
25
25
  end
26
26
 
27
27
  desc "Removes stale access grants"
@@ -33,7 +33,7 @@ namespace :doorkeeper do
33
33
  desc "Removes expired (TTL passed) access grants"
34
34
  task expired_grants: "doorkeeper:setup" do
35
35
  cleaner = Doorkeeper::StaleRecordsCleaner.new(Doorkeeper::AccessGrant)
36
- cleaner.clean_expired(Doorkeeper.configuration.authorization_code_expires_in)
36
+ cleaner.clean_expired(Doorkeeper.config.authorization_code_expires_in)
37
37
  end
38
38
  end
39
39
  end
@@ -7,10 +7,10 @@ module Doorkeeper
7
7
 
8
8
  def request
9
9
  @request ||= OAuth::AuthorizationCodeRequest.new(
10
- Doorkeeper.configuration,
10
+ Doorkeeper.config,
11
11
  grant,
12
12
  client,
13
- parameters
13
+ parameters,
14
14
  )
15
15
  end
16
16
 
@@ -19,7 +19,7 @@ module Doorkeeper
19
19
  def grant
20
20
  raise Errors::MissingRequiredParameter, :code if parameters[:code].blank?
21
21
 
22
- AccessGrant.by_token(parameters[:code])
22
+ Doorkeeper.config.access_grant_model.by_token(parameters[:code])
23
23
  end
24
24
  end
25
25
  end
@@ -7,9 +7,9 @@ module Doorkeeper
7
7
 
8
8
  def request
9
9
  @request ||= OAuth::ClientCredentialsRequest.new(
10
- Doorkeeper.configuration,
10
+ Doorkeeper.config,
11
11
  client,
12
- parameters
12
+ parameters,
13
13
  )
14
14
  end
15
15
  end
@@ -7,10 +7,10 @@ module Doorkeeper
7
7
 
8
8
  def request
9
9
  @request ||= OAuth::PasswordAccessTokenRequest.new(
10
- Doorkeeper.configuration,
10
+ Doorkeeper.config,
11
11
  client,
12
12
  resource_owner,
13
- parameters
13
+ parameters,
14
14
  )
15
15
  end
16
16
  end
@@ -6,14 +6,14 @@ module Doorkeeper
6
6
  delegate :credentials, :parameters, to: :server
7
7
 
8
8
  def refresh_token
9
- AccessToken.by_refresh_token(parameters[:refresh_token])
9
+ Doorkeeper.config.access_token_model.by_refresh_token(parameters[:refresh_token])
10
10
  end
11
11
 
12
12
  def request
13
13
  @request ||= OAuth::RefreshTokenRequest.new(
14
- Doorkeeper.configuration,
14
+ Doorkeeper.config,
15
15
  refresh_token, credentials,
16
- parameters
16
+ parameters,
17
17
  )
18
18
  end
19
19
  end
@@ -24,7 +24,7 @@ module Doorkeeper
24
24
  private
25
25
 
26
26
  def token_grant_types
27
- Doorkeeper.configuration.token_grant_types
27
+ Doorkeeper.config.token_grant_types
28
28
  end
29
29
 
30
30
  def build_strategy_class(grant_or_request_type)
@@ -37,7 +37,7 @@ module Doorkeeper
37
37
  end
38
38
 
39
39
  def credentials
40
- methods = Doorkeeper.configuration.client_credentials_methods
40
+ methods = Doorkeeper.config.client_credentials_methods
41
41
  @credentials ||= OAuth::Client::Credentials.from_request(context.request, *methods)
42
42
  end
43
43
  end
@@ -14,7 +14,7 @@ module Doorkeeper
14
14
  end
15
15
 
16
16
  def self.configured_orm
17
- Doorkeeper.configuration.orm
17
+ Doorkeeper.config.orm
18
18
  end
19
19
 
20
20
  def self.new(base_scope)
@@ -8,7 +8,7 @@ module Doorkeeper
8
8
  module VERSION
9
9
  # Semantic versioning
10
10
  MAJOR = 5
11
- MINOR = 2
11
+ MINOR = 3
12
12
  TINY = 0
13
13
  PRE = nil
14
14
 
data/lib/doorkeeper.rb CHANGED
@@ -38,10 +38,9 @@ require "doorkeeper/oauth/authorization_code_request"
38
38
  require "doorkeeper/oauth/refresh_token_request"
39
39
  require "doorkeeper/oauth/password_access_token_request"
40
40
 
41
- require "doorkeeper/oauth/client_credentials/validation"
41
+ require "doorkeeper/oauth/client_credentials/validator"
42
42
  require "doorkeeper/oauth/client_credentials/creator"
43
43
  require "doorkeeper/oauth/client_credentials/issuer"
44
- require "doorkeeper/oauth/client_credentials/validation"
45
44
  require "doorkeeper/oauth/client/credentials"
46
45
 
47
46
  require "doorkeeper/oauth/client_credentials_request"
@@ -85,7 +84,7 @@ require "doorkeeper/orm/active_record"
85
84
  # Main Doorkeeper namespace.
86
85
  #
87
86
  module Doorkeeper
88
- def self.authenticate(request, methods = Doorkeeper.configuration.access_token_methods)
87
+ def self.authenticate(request, methods = Doorkeeper.config.access_token_methods)
89
88
  OAuth::Token.authenticate(request, *methods)
90
89
  end
91
90
  end
@@ -16,7 +16,7 @@ module Doorkeeper
16
16
  migration_template(
17
17
  "add_owner_to_application_migration.rb.erb",
18
18
  "db/migrate/add_owner_to_application.rb",
19
- migration_version: migration_version
19
+ migration_version: migration_version,
20
20
  )
21
21
  end
22
22
 
@@ -16,7 +16,7 @@ module Doorkeeper
16
16
  migration_template(
17
17
  "add_confidential_to_applications.rb.erb",
18
18
  "db/migrate/add_confidential_to_applications.rb",
19
- migration_version: migration_version
19
+ migration_version: migration_version,
20
20
  )
21
21
  end
22
22
 
@@ -15,7 +15,7 @@ module Doorkeeper
15
15
  migration_template(
16
16
  "migration.rb.erb",
17
17
  "db/migrate/create_doorkeeper_tables.rb",
18
- migration_version: migration_version
18
+ migration_version: migration_version,
19
19
  )
20
20
  end
21
21
 
@@ -16,7 +16,7 @@ module Doorkeeper
16
16
  migration_template(
17
17
  "enable_pkce_migration.rb.erb",
18
18
  "db/migrate/enable_pkce.rb",
19
- migration_version: migration_version
19
+ migration_version: migration_version,
20
20
  )
21
21
  end
22
22
 
@@ -21,7 +21,7 @@ module Doorkeeper
21
21
 
22
22
  migration_template(
23
23
  "add_previous_refresh_token_to_access_tokens.rb.erb",
24
- "db/migrate/add_previous_refresh_token_to_access_tokens.rb"
24
+ "db/migrate/add_previous_refresh_token_to_access_tokens.rb",
25
25
  )
26
26
  end
27
27
 
@@ -34,7 +34,7 @@ module Doorkeeper
34
34
  def no_previous_refresh_token_column?
35
35
  !ActiveRecord::Base.connection.column_exists?(
36
36
  :oauth_access_tokens,
37
- :previous_refresh_token
37
+ :previous_refresh_token,
38
38
  )
39
39
  end
40
40
  end
@@ -29,6 +29,35 @@ Doorkeeper.configure do
29
29
  # end
30
30
  # end
31
31
 
32
+ # You can use your own model classes if you need to extend (or even override) default
33
+ # Doorkeeper models such as `Application`, `AccessToken` and `AccessGrant.
34
+ #
35
+ # Be default Doorkeeper ActiveRecord ORM uses it's own classes:
36
+ #
37
+ # access_token_class "Doorkeeper::AccessToken"
38
+ # access_grant_class "Doorkeeper::AccessGrant"
39
+ # application_class "Doorkeeper::Application"
40
+ #
41
+ # Don't forget to include Doorkeeper ORM mixins into your custom models:
42
+ #
43
+ # * ::Doorkeeper::Orm::ActiveRecord::Mixins::AccessToken - for access token
44
+ # * ::Doorkeeper::Orm::ActiveRecord::Mixins::AccessGrant - for access grant
45
+ # * ::Doorkeeper::Orm::ActiveRecord::Mixins::Application - for application (OAuth2 clients)
46
+ #
47
+ # For example:
48
+ #
49
+ # access_token_class "MyAccessToken"
50
+ #
51
+ # class MyAccessToken < ApplicationRecord
52
+ # include ::Doorkeeper::Orm::ActiveRecord::Mixins::AccessToken
53
+ #
54
+ # self.table_name = "hey_i_wanna_my_name"
55
+ #
56
+ # def destroy_me!
57
+ # destroy
58
+ # end
59
+ # end
60
+
32
61
  # If you are planning to use Doorkeeper in Rails 5 API-only application, then you might
33
62
  # want to use API mode that will skip all the views management and change the way how
34
63
  # Doorkeeper responds to a requests.
@@ -98,6 +127,16 @@ Doorkeeper.configure do
98
127
  #
99
128
  # token_reuse_limit 100
100
129
 
130
+ # Only allow one valid access token obtained via client credentials
131
+ # per client. If a new access token is obtained before the old one
132
+ # expired, the old one gets revoked (disabled by default)
133
+ #
134
+ # When enabling this option, make sure that you do not expect multiple processes
135
+ # using the same credentials at the same time (e.g. web servers spanning
136
+ # multiple machines and/or processes).
137
+ #
138
+ # revoke_previous_client_credentials_token
139
+
101
140
  # Hash access and refresh tokens before persisting them.
102
141
  # This will disable the possibility to use +reuse_access_token+
103
142
  # since plain values can no longer be retrieved.
@@ -21,7 +21,7 @@ describe Doorkeeper::ApplicationMetalController do
21
21
  end
22
22
 
23
23
  describe "enforce_content_type" do
24
- before { allow(Doorkeeper.configuration).to receive(:enforce_content_type).and_return(flag) }
24
+ before { allow(Doorkeeper.config).to receive(:enforce_content_type).and_return(flag) }
25
25
 
26
26
  context "enabled" do
27
27
  let(:flag) { true }
@@ -117,7 +117,7 @@ module Doorkeeper
117
117
 
118
118
  context "when admin is not authenticated" do
119
119
  before do
120
- allow(Doorkeeper.configuration).to receive(:authenticate_admin).and_return(proc do
120
+ allow(Doorkeeper.config).to receive(:authenticate_admin).and_return(proc do
121
121
  redirect_to main_app.root_url
122
122
  end)
123
123
  end
@@ -142,7 +142,8 @@ module Doorkeeper
142
142
  context "when admin is authenticated" do
143
143
  context "when application secrets are hashed" do
144
144
  before do
145
- allow(Doorkeeper.configuration).to receive(:application_secret_strategy).and_return(Doorkeeper::SecretStoring::Sha256Hash)
145
+ allow(Doorkeeper.configuration)
146
+ .to receive(:application_secret_strategy).and_return(Doorkeeper::SecretStoring::Sha256Hash)
146
147
  end
147
148
 
148
149
  it "shows the application secret after creating a new application" do
@@ -27,8 +27,10 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
27
27
  end)
28
28
  end
29
29
 
30
- allow(Doorkeeper.configuration).to receive(:grant_flows).and_return(["implicit"])
31
- allow(controller).to receive(:current_resource_owner).and_return(user)
30
+ allow(Doorkeeper.config).to receive(:grant_flows).and_return(["implicit"])
31
+ allow(Doorkeeper.config).to receive(:authenticate_resource_owner).and_return(->(_) { authenticator_method })
32
+ allow(controller).to receive(:authenticator_method).and_return(user)
33
+ expect(controller).to receive(:authenticator_method).at_most(:once)
32
34
  end
33
35
 
34
36
  describe "POST #create" do
@@ -67,7 +69,7 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
67
69
 
68
70
  describe "POST #create in API mode" do
69
71
  before do
70
- allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
72
+ allow(Doorkeeper.config).to receive(:api_only).and_return(true)
71
73
  post :create, params: { client_id: client.uid, response_type: "token", redirect_uri: client.redirect_uri }
72
74
  end
73
75
 
@@ -125,7 +127,7 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
125
127
 
126
128
  it "includes error description" do
127
129
  expect(response_json_body["error_description"]).to eq(
128
- translated_invalid_request_error_message(:missing_param, :client_id)
130
+ translated_invalid_request_error_message(:missing_param, :client_id),
129
131
  )
130
132
  end
131
133
 
@@ -175,7 +177,7 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
175
177
  describe "POST #create in API mode with errors" do
176
178
  context "when missing client_id" do
177
179
  before do
178
- allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
180
+ allow(Doorkeeper.config).to receive(:api_only).and_return(true)
179
181
 
180
182
  post :create, params: {
181
183
  client_id: "",
@@ -196,7 +198,7 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
196
198
 
197
199
  it "includes error description" do
198
200
  expect(response_json_body["error_description"]).to eq(
199
- translated_invalid_request_error_message(:missing_param, :client_id)
201
+ translated_invalid_request_error_message(:missing_param, :client_id),
200
202
  )
201
203
  end
202
204
 
@@ -207,7 +209,7 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
207
209
 
208
210
  context "when other error happens" do
209
211
  before do
210
- allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
212
+ allow(Doorkeeper.config).to receive(:api_only).and_return(true)
211
213
  default_scopes_exist :public
212
214
 
213
215
  post :create, params: {
@@ -249,7 +251,7 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
249
251
 
250
252
  describe "POST #create with application already authorized" do
251
253
  before do
252
- allow(Doorkeeper.configuration).to receive(:reuse_access_token).and_return(true)
254
+ allow(Doorkeeper.config).to receive(:reuse_access_token).and_return(true)
253
255
 
254
256
  access_token.save!
255
257
 
@@ -284,12 +286,12 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
284
286
  end
285
287
 
286
288
  it "should call :before_successful_authorization callback" do
287
- expect(Doorkeeper.configuration)
289
+ expect(Doorkeeper.config)
288
290
  .to receive_message_chain(:before_successful_authorization, :call).with(instance_of(described_class))
289
291
  end
290
292
 
291
293
  it "should call :after_successful_authorization callback" do
292
- expect(Doorkeeper.configuration)
294
+ expect(Doorkeeper.config)
293
295
  .to receive_message_chain(:after_successful_authorization, :call).with(instance_of(described_class))
294
296
  end
295
297
  end
@@ -300,18 +302,18 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
300
302
  end
301
303
 
302
304
  it "should not call :before_successful_authorization callback" do
303
- expect(Doorkeeper.configuration).not_to receive(:before_successful_authorization)
305
+ expect(Doorkeeper.config).not_to receive(:before_successful_authorization)
304
306
  end
305
307
 
306
308
  it "should not call :after_successful_authorization callback" do
307
- expect(Doorkeeper.configuration).not_to receive(:after_successful_authorization)
309
+ expect(Doorkeeper.config).not_to receive(:after_successful_authorization)
308
310
  end
309
311
  end
310
312
  end
311
313
 
312
314
  describe "GET #new token request with native url and skip_authorization true" do
313
315
  before do
314
- allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc do
316
+ allow(Doorkeeper.config).to receive(:skip_authorization).and_return(proc do
315
317
  true
316
318
  end)
317
319
 
@@ -340,8 +342,8 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
340
342
 
341
343
  describe "GET #new code request with native url and skip_authorization true" do
342
344
  before do
343
- allow(Doorkeeper.configuration).to receive(:grant_flows).and_return(%w[authorization_code])
344
- allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc do
345
+ allow(Doorkeeper.config).to receive(:grant_flows).and_return(%w[authorization_code])
346
+ allow(Doorkeeper.config).to receive(:skip_authorization).and_return(proc do
345
347
  true
346
348
  end)
347
349
 
@@ -371,7 +373,7 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
371
373
 
372
374
  describe "GET #new with skip_authorization true" do
373
375
  before do
374
- allow(Doorkeeper.configuration).to receive(:skip_authorization).and_return(proc do
376
+ allow(Doorkeeper.config).to receive(:skip_authorization).and_return(proc do
375
377
  true
376
378
  end)
377
379
 
@@ -410,7 +412,7 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
410
412
 
411
413
  describe "GET #new in API mode" do
412
414
  before do
413
- allow(Doorkeeper.configuration).to receive(:api_only).and_return(true)
415
+ allow(Doorkeeper.config).to receive(:api_only).and_return(true)
414
416
 
415
417
  get :new, params: {
416
418
  client_id: client.uid,
@@ -466,7 +468,7 @@ describe Doorkeeper::AuthorizationsController, "implicit grant flow" do
466
468
  expect(redirect_uri.match(/token_type=(\w+)&?/)[1]).to eq "Bearer"
467
469
  expect(redirect_uri.match(/expires_in=(\d+)&?/)[1].to_i).to eq 1234
468
470
  expect(
469
- redirect_uri.match(/access_token=([a-zA-Z0-9\-_]+)&?/)[1]
471
+ redirect_uri.match(/access_token=([a-zA-Z0-9\-_]+)&?/)[1],
470
472
  ).to eq Doorkeeper::AccessToken.first.token
471
473
  end
472
474
 
@@ -28,9 +28,11 @@ describe "doorkeeper authorize filter" do
28
28
 
29
29
  let(:token_string) { "1A2BC3" }
30
30
  let(:token) do
31
- double(Doorkeeper::AccessToken,
32
- acceptable?: true, previous_refresh_token: "",
33
- revoke_previous_refresh_token!: true)
31
+ double(
32
+ Doorkeeper::AccessToken,
33
+ acceptable?: true, previous_refresh_token: "",
34
+ revoke_previous_refresh_token!: true,
35
+ )
34
36
  end
35
37
 
36
38
  it "access_token param" do
@@ -108,13 +110,15 @@ describe "doorkeeper authorize filter" do
108
110
  let(:token_string) { "1A2DUWE" }
109
111
 
110
112
  it "allows if the token has particular scopes" do
111
- token = double(Doorkeeper::AccessToken,
112
- accessible?: true, scopes: %w[write public],
113
- previous_refresh_token: "",
114
- revoke_previous_refresh_token!: true)
113
+ token = double(
114
+ Doorkeeper::AccessToken,
115
+ accessible?: true, scopes: %w[write public],
116
+ previous_refresh_token: "",
117
+ revoke_previous_refresh_token!: true,
118
+ )
115
119
  expect(token).to receive(:acceptable?).with([:write]).and_return(true)
116
120
  expect(
117
- Doorkeeper::AccessToken
121
+ Doorkeeper::AccessToken,
118
122
  ).to receive(:by_token).with(token_string).and_return(token)
119
123
 
120
124
  get :index, params: { access_token: token_string }
@@ -122,12 +126,14 @@ describe "doorkeeper authorize filter" do
122
126
  end
123
127
 
124
128
  it "does not allow if the token does not include given scope" do
125
- token = double(Doorkeeper::AccessToken,
126
- accessible?: true, scopes: ["public"], revoked?: false,
127
- expired?: false, previous_refresh_token: "",
128
- revoke_previous_refresh_token!: true)
129
+ token = double(
130
+ Doorkeeper::AccessToken,
131
+ accessible?: true, scopes: ["public"], revoked?: false,
132
+ expired?: false, previous_refresh_token: "",
133
+ revoke_previous_refresh_token!: true,
134
+ )
129
135
  expect(
130
- Doorkeeper::AccessToken
136
+ Doorkeeper::AccessToken,
131
137
  ).to receive(:by_token).with(token_string).and_return(token)
132
138
  expect(token).to receive(:acceptable?).with([:write]).and_return(false)
133
139
 
@@ -224,10 +230,12 @@ describe "doorkeeper authorize filter" do
224
230
  end
225
231
 
226
232
  let(:token) do
227
- double(Doorkeeper::AccessToken,
228
- accessible?: true, scopes: ["public"], revoked?: false,
229
- expired?: false, previous_refresh_token: "",
230
- revoke_previous_refresh_token!: true)
233
+ double(
234
+ Doorkeeper::AccessToken,
235
+ accessible?: true, scopes: ["public"], revoked?: false,
236
+ expired?: false, previous_refresh_token: "",
237
+ revoke_previous_refresh_token!: true,
238
+ )
231
239
  end
232
240
 
233
241
  let(:token_string) { "1A2DUWE" }
@@ -42,7 +42,7 @@ describe Doorkeeper::TokenInfoController do
42
42
  get :show
43
43
 
44
44
  expect(response.body).to eq(
45
- Doorkeeper::OAuth::InvalidTokenResponse.new.body.to_json
45
+ Doorkeeper::OAuth::InvalidTokenResponse.new.body.to_json,
46
46
  )
47
47
  end
48
48
  end
@@ -142,7 +142,7 @@ describe Doorkeeper::TokensController do
142
142
  allow(I18n).to receive(:translate)
143
143
  .with(
144
144
  custom_message,
145
- hash_including(scope: %i[doorkeeper errors messages])
145
+ hash_including(scope: %i[doorkeeper errors messages]),
146
146
  )
147
147
  .and_return("Authorization custom message")
148
148
 
@@ -25,14 +25,14 @@ class CreateDoorkeeperTables < ActiveRecord::Migration[4.2]
25
25
  t.text :redirect_uri, null: false
26
26
  t.datetime :created_at, null: false
27
27
  t.datetime :revoked_at
28
- t.string :scopes, null: false, default: ""
28
+ t.string :scopes, null: false, default: ""
29
29
  end
30
30
 
31
31
  add_index :oauth_access_grants, :token, unique: true
32
32
  add_foreign_key(
33
33
  :oauth_access_grants,
34
34
  :oauth_applications,
35
- column: :application_id
35
+ column: :application_id,
36
36
  )
37
37
 
38
38
  create_table :oauth_access_tokens do |t|
@@ -59,7 +59,7 @@ class CreateDoorkeeperTables < ActiveRecord::Migration[4.2]
59
59
  add_foreign_key(
60
60
  :oauth_access_tokens,
61
61
  :oauth_applications,
62
- column: :application_id
62
+ column: :application_id,
63
63
  )
64
64
 
65
65
  # Uncomment below to ensure a valid reference to the resource owner's table