doorkeeper 5.2.6 → 5.3.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of doorkeeper might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Appraisals +2 -2
- data/CHANGELOG.md +24 -5
- data/Gemfile +2 -2
- data/app/controllers/doorkeeper/application_controller.rb +2 -2
- data/app/controllers/doorkeeper/application_metal_controller.rb +2 -2
- data/app/controllers/doorkeeper/authorizations_controller.rb +2 -2
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +2 -2
- data/gemfiles/rails_5_0.gemfile +2 -2
- data/gemfiles/rails_5_1.gemfile +2 -2
- data/gemfiles/rails_5_2.gemfile +2 -2
- data/gemfiles/rails_6_0.gemfile +2 -2
- data/gemfiles/rails_master.gemfile +2 -2
- data/lib/doorkeeper/config.rb +71 -38
- data/lib/doorkeeper/grape/helpers.rb +1 -1
- data/lib/doorkeeper/helpers/controller.rb +10 -8
- data/lib/doorkeeper/models/access_grant_mixin.rb +7 -6
- data/lib/doorkeeper/models/access_token_mixin.rb +54 -16
- data/lib/doorkeeper/models/application_mixin.rb +3 -3
- data/lib/doorkeeper/models/concerns/ownership.rb +1 -1
- data/lib/doorkeeper/models/concerns/reusable.rb +1 -1
- data/lib/doorkeeper/models/concerns/revocable.rb +0 -27
- data/lib/doorkeeper/oauth/authorization/code.rb +4 -4
- data/lib/doorkeeper/oauth/authorization/token.rb +9 -6
- data/lib/doorkeeper/oauth/authorization_code_request.rb +13 -6
- data/lib/doorkeeper/oauth/base_request.rb +8 -4
- data/lib/doorkeeper/oauth/client.rb +7 -8
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +16 -9
- data/lib/doorkeeper/oauth/client_credentials/issuer.rb +7 -7
- data/lib/doorkeeper/oauth/client_credentials/{validation.rb → validator.rb} +4 -4
- data/lib/doorkeeper/oauth/client_credentials_request.rb +1 -1
- data/lib/doorkeeper/oauth/code_response.rb +2 -2
- data/lib/doorkeeper/oauth/error.rb +1 -1
- data/lib/doorkeeper/oauth/error_response.rb +5 -5
- data/lib/doorkeeper/oauth/helpers/scope_checker.rb +7 -5
- data/lib/doorkeeper/oauth/helpers/unique_token.rb +8 -5
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +1 -1
- data/lib/doorkeeper/oauth/invalid_request_response.rb +3 -3
- data/lib/doorkeeper/oauth/invalid_token_response.rb +5 -2
- data/lib/doorkeeper/oauth/password_access_token_request.rb +3 -3
- data/lib/doorkeeper/oauth/pre_authorization.rb +7 -5
- data/lib/doorkeeper/oauth/refresh_token_request.rb +5 -5
- data/lib/doorkeeper/oauth/token.rb +2 -2
- data/lib/doorkeeper/oauth/token_introspection.rb +6 -6
- data/lib/doorkeeper/orm/active_record/access_grant.rb +4 -43
- data/lib/doorkeeper/orm/active_record/access_token.rb +4 -35
- data/lib/doorkeeper/orm/active_record/application.rb +3 -155
- data/lib/doorkeeper/orm/active_record/mixins/access_grant.rb +53 -0
- data/lib/doorkeeper/orm/active_record/mixins/access_token.rb +47 -0
- data/lib/doorkeeper/orm/active_record/mixins/application.rb +187 -0
- data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +3 -3
- data/lib/doorkeeper/orm/active_record.rb +3 -3
- data/lib/doorkeeper/rails/helpers.rb +4 -4
- data/lib/doorkeeper/rails/routes.rb +5 -7
- data/lib/doorkeeper/rake/db.rake +3 -3
- data/lib/doorkeeper/request/authorization_code.rb +3 -3
- data/lib/doorkeeper/request/client_credentials.rb +2 -2
- data/lib/doorkeeper/request/password.rb +2 -2
- data/lib/doorkeeper/request/refresh_token.rb +3 -3
- data/lib/doorkeeper/request.rb +1 -1
- data/lib/doorkeeper/server.rb +1 -1
- data/lib/doorkeeper/stale_records_cleaner.rb +1 -1
- data/lib/doorkeeper/version.rb +2 -2
- data/lib/doorkeeper.rb +2 -3
- data/lib/generators/doorkeeper/application_owner_generator.rb +1 -1
- data/lib/generators/doorkeeper/confidential_applications_generator.rb +1 -1
- data/lib/generators/doorkeeper/migration_generator.rb +1 -1
- data/lib/generators/doorkeeper/pkce_generator.rb +1 -1
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +2 -2
- data/lib/generators/doorkeeper/templates/initializer.rb +39 -0
- data/spec/controllers/application_metal_controller_spec.rb +1 -1
- data/spec/controllers/applications_controller_spec.rb +3 -2
- data/spec/controllers/authorizations_controller_spec.rb +18 -18
- data/spec/controllers/protected_resources_controller_spec.rb +25 -17
- data/spec/controllers/token_info_controller_spec.rb +1 -1
- data/spec/controllers/tokens_controller_spec.rb +1 -1
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +3 -3
- data/spec/dummy/db/migrate/20160320211015_add_previous_refresh_token_to_access_tokens.rb +1 -1
- data/spec/dummy/db/migrate/20180210183654_add_confidential_to_applications.rb +1 -1
- data/spec/generators/install_generator_spec.rb +1 -1
- data/spec/generators/previous_refresh_token_generator_spec.rb +2 -2
- data/spec/helpers/doorkeeper/dashboard_helper_spec.rb +1 -1
- data/spec/lib/config_spec.rb +62 -7
- data/spec/lib/doorkeeper_spec.rb +1 -1
- data/spec/lib/models/revocable_spec.rb +3 -3
- data/spec/lib/oauth/authorization_code_request_spec.rb +127 -125
- data/spec/lib/oauth/base_request_spec.rb +160 -158
- data/spec/lib/oauth/base_response_spec.rb +27 -29
- data/spec/lib/oauth/client/credentials_spec.rb +1 -1
- data/spec/lib/oauth/client_credentials/creator_spec.rb +42 -5
- data/spec/lib/oauth/client_credentials/issuer_spec.rb +12 -12
- data/spec/lib/oauth/client_credentials/validation_spec.rb +4 -4
- data/spec/lib/oauth/client_credentials_integration_spec.rb +16 -18
- data/spec/lib/oauth/client_credentials_request_spec.rb +78 -80
- data/spec/lib/oauth/client_spec.rb +26 -26
- data/spec/lib/oauth/code_request_spec.rb +34 -34
- data/spec/lib/oauth/code_response_spec.rb +21 -25
- data/spec/lib/oauth/error_response_spec.rb +42 -44
- data/spec/lib/oauth/error_spec.rb +12 -14
- data/spec/lib/oauth/forbidden_token_response_spec.rb +11 -13
- data/spec/lib/oauth/helpers/scope_checker_spec.rb +30 -18
- data/spec/lib/oauth/invalid_request_response_spec.rb +48 -50
- data/spec/lib/oauth/invalid_token_response_spec.rb +32 -34
- data/spec/lib/oauth/password_access_token_request_spec.rb +145 -147
- data/spec/lib/oauth/pre_authorization_spec.rb +159 -161
- data/spec/lib/oauth/refresh_token_request_spec.rb +138 -139
- data/spec/lib/oauth/scopes_spec.rb +104 -106
- data/spec/lib/oauth/token_request_spec.rb +115 -111
- data/spec/lib/oauth/token_response_spec.rb +71 -73
- data/spec/lib/oauth/token_spec.rb +121 -123
- data/spec/models/doorkeeper/access_grant_spec.rb +3 -5
- data/spec/models/doorkeeper/access_token_spec.rb +7 -7
- data/spec/models/doorkeeper/application_spec.rb +2 -2
- data/spec/requests/applications/applications_request_spec.rb +1 -1
- data/spec/requests/endpoints/authorization_spec.rb +5 -3
- data/spec/requests/flows/authorization_code_spec.rb +34 -22
- data/spec/requests/flows/client_credentials_spec.rb +1 -1
- data/spec/requests/flows/password_spec.rb +32 -12
- data/spec/requests/flows/refresh_token_spec.rb +19 -19
- data/spec/requests/flows/revoke_token_spec.rb +18 -12
- data/spec/spec_helper.rb +1 -4
- data/spec/support/shared/controllers_shared_context.rb +33 -23
- data/spec/validators/redirect_uri_validator_spec.rb +1 -1
- metadata +6 -5
- data/spec/support/http_method_shim.rb +0 -29
@@ -0,0 +1,187 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Doorkeeper::Orm::ActiveRecord::Mixins
|
4
|
+
module Application
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
self.table_name = "#{table_name_prefix}oauth_applications#{table_name_suffix}"
|
9
|
+
|
10
|
+
include ::Doorkeeper::ApplicationMixin
|
11
|
+
|
12
|
+
has_many :access_grants,
|
13
|
+
foreign_key: :application_id,
|
14
|
+
dependent: :delete_all,
|
15
|
+
class_name: Doorkeeper.config.access_grant_class.to_s
|
16
|
+
|
17
|
+
has_many :access_tokens,
|
18
|
+
foreign_key: :application_id,
|
19
|
+
dependent: :delete_all,
|
20
|
+
class_name: Doorkeeper.config.access_token_class.to_s
|
21
|
+
|
22
|
+
validates :name, :secret, :uid, presence: true
|
23
|
+
validates :uid, uniqueness: { case_sensitive: true }
|
24
|
+
validates :redirect_uri, "doorkeeper/redirect_uri": true
|
25
|
+
validates :confidential, inclusion: { in: [true, false] }
|
26
|
+
|
27
|
+
validate :scopes_match_configured, if: :enforce_scopes?
|
28
|
+
|
29
|
+
before_validation :generate_uid, :generate_secret, on: :create
|
30
|
+
|
31
|
+
has_many :authorized_tokens,
|
32
|
+
-> { where(revoked_at: nil) },
|
33
|
+
foreign_key: :application_id,
|
34
|
+
class_name: Doorkeeper.config.access_token_class.to_s
|
35
|
+
|
36
|
+
has_many :authorized_applications,
|
37
|
+
through: :authorized_tokens,
|
38
|
+
source: :application
|
39
|
+
|
40
|
+
# Generates a new secret for this application, intended to be used
|
41
|
+
# for rotating the secret or in case of compromise.
|
42
|
+
#
|
43
|
+
# @return [String] new transformed secret value
|
44
|
+
#
|
45
|
+
def renew_secret
|
46
|
+
@raw_secret = Doorkeeper::OAuth::Helpers::UniqueToken.generate
|
47
|
+
secret_strategy.store_secret(self, :secret, @raw_secret)
|
48
|
+
end
|
49
|
+
|
50
|
+
# We keep a volatile copy of the raw secret for initial communication
|
51
|
+
# The stored refresh_token may be mapped and not available in cleartext.
|
52
|
+
#
|
53
|
+
# Some strategies allow restoring stored secrets (e.g. symmetric encryption)
|
54
|
+
# while hashing strategies do not, so you cannot rely on this value
|
55
|
+
# returning a present value for persisted tokens.
|
56
|
+
def plaintext_secret
|
57
|
+
if secret_strategy.allows_restoring_secrets?
|
58
|
+
secret_strategy.restore_secret(self, :secret)
|
59
|
+
else
|
60
|
+
@raw_secret
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Represents client as set of it's attributes in JSON format.
|
65
|
+
# This is the right way how we want to override ActiveRecord #to_json.
|
66
|
+
#
|
67
|
+
# Respects privacy settings and serializes minimum set of attributes
|
68
|
+
# for public/private clients and full set for authorized owners.
|
69
|
+
#
|
70
|
+
# @return [Hash] entity attributes for JSON
|
71
|
+
#
|
72
|
+
def as_json(options = {})
|
73
|
+
# if application belongs to some owner we need to check if it's the same as
|
74
|
+
# the one passed in the options or check if we render the client as an owner
|
75
|
+
if (respond_to?(:owner) && owner && owner == options[:current_resource_owner]) ||
|
76
|
+
options[:as_owner]
|
77
|
+
# Owners can see all the client attributes, fallback to ActiveModel serialization
|
78
|
+
super
|
79
|
+
else
|
80
|
+
# if application has no owner or it's owner doesn't match one from the options
|
81
|
+
# we render only minimum set of attributes that could be exposed to a public
|
82
|
+
only = extract_serializable_attributes(options)
|
83
|
+
super(options.merge(only: only))
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def authorized_for_resource_owner?(resource_owner)
|
88
|
+
Doorkeeper.configuration.authorize_resource_owner_for_client.call(self, resource_owner)
|
89
|
+
end
|
90
|
+
|
91
|
+
# We need to hook into this method to allow serializing plan-text secrets
|
92
|
+
# when secrets hashing enabled.
|
93
|
+
#
|
94
|
+
# @param key [String] attribute name
|
95
|
+
#
|
96
|
+
def read_attribute_for_serialization(key)
|
97
|
+
return super unless key.to_s == "secret"
|
98
|
+
|
99
|
+
plaintext_secret || secret
|
100
|
+
end
|
101
|
+
|
102
|
+
private
|
103
|
+
|
104
|
+
def generate_uid
|
105
|
+
self.uid = Doorkeeper::OAuth::Helpers::UniqueToken.generate if uid.blank?
|
106
|
+
end
|
107
|
+
|
108
|
+
def generate_secret
|
109
|
+
return if secret.present?
|
110
|
+
|
111
|
+
renew_secret
|
112
|
+
end
|
113
|
+
|
114
|
+
def scopes_match_configured
|
115
|
+
if scopes.present? && !Doorkeeper::OAuth::Helpers::ScopeChecker.valid?(
|
116
|
+
scope_str: scopes.to_s,
|
117
|
+
server_scopes: Doorkeeper.config.scopes,
|
118
|
+
)
|
119
|
+
errors.add(:scopes, :not_match_configured)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def enforce_scopes?
|
124
|
+
Doorkeeper.config.enforce_configured_scopes?
|
125
|
+
end
|
126
|
+
|
127
|
+
# Helper method to extract collection of serializable attribute names
|
128
|
+
# considering serialization options (like `only`, `except` and so on).
|
129
|
+
#
|
130
|
+
# @param options [Hash] serialization options
|
131
|
+
#
|
132
|
+
# @return [Array<String>]
|
133
|
+
# collection of attributes to be serialized using #as_json
|
134
|
+
#
|
135
|
+
def extract_serializable_attributes(options = {})
|
136
|
+
opts = options.try(:dup) || {}
|
137
|
+
only = Array.wrap(opts[:only]).map(&:to_s)
|
138
|
+
|
139
|
+
only = if only.blank?
|
140
|
+
serializable_attributes
|
141
|
+
else
|
142
|
+
only & serializable_attributes
|
143
|
+
end
|
144
|
+
|
145
|
+
only -= Array.wrap(opts[:except]).map(&:to_s) if opts.key?(:except)
|
146
|
+
only.uniq
|
147
|
+
end
|
148
|
+
|
149
|
+
# Collection of attributes that could be serialized for public.
|
150
|
+
# Override this method if you need additional attributes to be serialized.
|
151
|
+
#
|
152
|
+
# @return [Array<String>] collection of serializable attributes
|
153
|
+
def serializable_attributes
|
154
|
+
attributes = %w[id name created_at]
|
155
|
+
attributes << "uid" unless confidential?
|
156
|
+
attributes
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
module ClassMethods
|
161
|
+
# Returns Applications associated with active (not revoked) Access Tokens
|
162
|
+
# that are owned by the specific Resource Owner.
|
163
|
+
#
|
164
|
+
# @param resource_owner [ActiveRecord::Base]
|
165
|
+
# Resource Owner model instance
|
166
|
+
#
|
167
|
+
# @return [ActiveRecord::Relation]
|
168
|
+
# Applications authorized for the Resource Owner
|
169
|
+
#
|
170
|
+
def authorized_for(resource_owner)
|
171
|
+
resource_access_tokens = Doorkeeper.config.access_token_model.active_for(resource_owner)
|
172
|
+
where(id: resource_access_tokens.select(:application_id).distinct)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Revokes AccessToken and AccessGrant records that have not been revoked and
|
176
|
+
# associated with the specific Application and Resource Owner.
|
177
|
+
#
|
178
|
+
# @param resource_owner [ActiveRecord::Base]
|
179
|
+
# instance of the Resource Owner model
|
180
|
+
#
|
181
|
+
def revoke_tokens_and_grants_for(id, resource_owner)
|
182
|
+
Doorkeeper.config.access_token_model.revoke_all_for(id, resource_owner)
|
183
|
+
Doorkeeper.config.access_grant_model.revoke_all_for(id, resource_owner)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -8,7 +8,7 @@ module Doorkeeper
|
|
8
8
|
class RedirectUriValidator < ActiveModel::EachValidator
|
9
9
|
def validate_each(record, attribute, value)
|
10
10
|
if value.blank?
|
11
|
-
return if Doorkeeper.
|
11
|
+
return if Doorkeeper.config.allow_blank_redirect_uri?(record)
|
12
12
|
|
13
13
|
record.errors.add(attribute, :blank)
|
14
14
|
else
|
@@ -34,7 +34,7 @@ module Doorkeeper
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def forbidden_uri?(uri)
|
37
|
-
Doorkeeper.
|
37
|
+
Doorkeeper.config.forbid_redirect_uri.call(uri)
|
38
38
|
end
|
39
39
|
|
40
40
|
def unspecified_scheme?(uri)
|
@@ -48,7 +48,7 @@ module Doorkeeper
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def invalid_ssl_uri?(uri)
|
51
|
-
forces_ssl = Doorkeeper.
|
51
|
+
forces_ssl = Doorkeeper.config.force_ssl_in_redirect_uri
|
52
52
|
non_https = uri.try(:scheme) == "http"
|
53
53
|
|
54
54
|
if forces_ssl.respond_to?(:call)
|
@@ -20,9 +20,9 @@ module Doorkeeper
|
|
20
20
|
require "doorkeeper/orm/active_record/access_token"
|
21
21
|
require "doorkeeper/orm/active_record/application"
|
22
22
|
|
23
|
-
if Doorkeeper.
|
23
|
+
if Doorkeeper.config.active_record_options[:establish_connection]
|
24
24
|
Doorkeeper::Orm::ActiveRecord.models.each do |model|
|
25
|
-
options = Doorkeeper.
|
25
|
+
options = Doorkeeper.config.active_record_options[:establish_connection]
|
26
26
|
model.establish_connection(options)
|
27
27
|
end
|
28
28
|
end
|
@@ -33,7 +33,7 @@ module Doorkeeper
|
|
33
33
|
lazy_load do
|
34
34
|
require "doorkeeper/models/concerns/ownership"
|
35
35
|
|
36
|
-
Doorkeeper
|
36
|
+
Doorkeeper.config.application_model.send :include, Doorkeeper::Models::Ownership
|
37
37
|
end
|
38
38
|
end
|
39
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.
|
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.
|
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.
|
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.
|
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.
|
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
|
|
data/lib/doorkeeper/rake/db.rake
CHANGED
@@ -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
|
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.
|
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.
|
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.
|
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
|
-
|
22
|
+
Doorkeeper.config.access_grant_model.by_token(parameters[:code])
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -6,14 +6,14 @@ module Doorkeeper
|
|
6
6
|
delegate :credentials, :parameters, to: :server
|
7
7
|
|
8
8
|
def refresh_token
|
9
|
-
|
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.
|
14
|
+
Doorkeeper.config,
|
15
15
|
refresh_token, credentials,
|
16
|
-
parameters
|
16
|
+
parameters,
|
17
17
|
)
|
18
18
|
end
|
19
19
|
end
|
data/lib/doorkeeper/request.rb
CHANGED
data/lib/doorkeeper/server.rb
CHANGED
@@ -37,7 +37,7 @@ module Doorkeeper
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def credentials
|
40
|
-
methods = Doorkeeper.
|
40
|
+
methods = Doorkeeper.config.client_credentials_methods
|
41
41
|
@credentials ||= OAuth::Client::Credentials.from_request(context.request, *methods)
|
42
42
|
end
|
43
43
|
end
|
data/lib/doorkeeper/version.rb
CHANGED
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/
|
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.
|
87
|
+
def self.authenticate(request, methods = Doorkeeper.config.access_token_methods)
|
89
88
|
OAuth::Token.authenticate(request, *methods)
|
90
89
|
end
|
91
90
|
end
|
@@ -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.
|
@@ -106,6 +135,16 @@ Doorkeeper.configure do
|
|
106
135
|
#
|
107
136
|
# token_reuse_limit 100
|
108
137
|
|
138
|
+
# Only allow one valid access token obtained via client credentials
|
139
|
+
# per client. If a new access token is obtained before the old one
|
140
|
+
# expired, the old one gets revoked (disabled by default)
|
141
|
+
#
|
142
|
+
# When enabling this option, make sure that you do not expect multiple processes
|
143
|
+
# using the same credentials at the same time (e.g. web servers spanning
|
144
|
+
# multiple machines and/or processes).
|
145
|
+
#
|
146
|
+
# revoke_previous_client_credentials_token
|
147
|
+
|
109
148
|
# Hash access and refresh tokens before persisting them.
|
110
149
|
# This will disable the possibility to use +reuse_access_token+
|
111
150
|
# 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.
|
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.
|
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)
|
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
|