doorkeeper 5.1.2 → 5.2.2
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 +1 -1
- data/CHANGELOG.md +854 -0
- data/CONTRIBUTING.md +11 -9
- data/Dangerfile +2 -2
- data/Dockerfile +29 -0
- data/Gemfile +3 -2
- data/NEWS.md +1 -819
- data/README.md +11 -3
- data/RELEASING.md +6 -5
- data/app/controllers/doorkeeper/application_controller.rb +1 -1
- data/app/controllers/doorkeeper/application_metal_controller.rb +2 -1
- data/app/controllers/doorkeeper/applications_controller.rb +5 -3
- data/app/controllers/doorkeeper/authorizations_controller.rb +14 -7
- data/app/controllers/doorkeeper/authorized_applications_controller.rb +1 -1
- data/app/controllers/doorkeeper/tokens_controller.rb +32 -9
- data/app/views/doorkeeper/applications/_form.html.erb +0 -6
- data/app/views/doorkeeper/applications/show.html.erb +1 -1
- data/config/locales/en.yml +8 -2
- data/doorkeeper.gemspec +9 -1
- data/gemfiles/rails_5_0.gemfile +1 -0
- data/gemfiles/rails_5_1.gemfile +1 -0
- data/gemfiles/rails_5_2.gemfile +1 -0
- data/gemfiles/rails_6_0.gemfile +2 -1
- data/gemfiles/rails_master.gemfile +1 -0
- data/lib/doorkeeper/config/option.rb +13 -7
- data/lib/doorkeeper/config.rb +88 -6
- data/lib/doorkeeper/errors.rb +13 -18
- data/lib/doorkeeper/grape/helpers.rb +5 -1
- data/lib/doorkeeper/helpers/controller.rb +23 -4
- data/lib/doorkeeper/models/access_token_mixin.rb +43 -2
- data/lib/doorkeeper/oauth/authorization/code.rb +11 -13
- data/lib/doorkeeper/oauth/authorization/token.rb +1 -1
- data/lib/doorkeeper/oauth/authorization_code_request.rb +18 -9
- data/lib/doorkeeper/oauth/base_request.rb +2 -0
- data/lib/doorkeeper/oauth/client_credentials/creator.rb +14 -0
- data/lib/doorkeeper/oauth/client_credentials/validation.rb +8 -0
- data/lib/doorkeeper/oauth/code_request.rb +5 -11
- data/lib/doorkeeper/oauth/code_response.rb +2 -2
- data/lib/doorkeeper/oauth/error_response.rb +1 -1
- data/lib/doorkeeper/oauth/helpers/uri_checker.rb +18 -4
- data/lib/doorkeeper/oauth/invalid_request_response.rb +43 -0
- data/lib/doorkeeper/oauth/nonstandard.rb +39 -0
- data/lib/doorkeeper/oauth/password_access_token_request.rb +7 -2
- data/lib/doorkeeper/oauth/pre_authorization.rb +70 -37
- data/lib/doorkeeper/oauth/refresh_token_request.rb +13 -10
- data/lib/doorkeeper/oauth/token_introspection.rb +23 -13
- data/lib/doorkeeper/oauth/token_request.rb +4 -18
- data/lib/doorkeeper/orm/active_record/access_grant.rb +1 -1
- data/lib/doorkeeper/orm/active_record/access_token.rb +2 -2
- data/lib/doorkeeper/orm/active_record/application.rb +15 -69
- data/lib/doorkeeper/orm/active_record/redirect_uri_validator.rb +61 -0
- data/lib/doorkeeper/orm/active_record.rb +19 -3
- data/lib/doorkeeper/request/authorization_code.rb +2 -0
- data/lib/doorkeeper/request.rb +6 -11
- data/lib/doorkeeper/server.rb +2 -6
- data/lib/doorkeeper/stale_records_cleaner.rb +6 -2
- data/lib/doorkeeper/version.rb +1 -1
- data/lib/doorkeeper.rb +4 -0
- data/lib/generators/doorkeeper/previous_refresh_token_generator.rb +6 -6
- data/lib/generators/doorkeeper/templates/initializer.rb +110 -33
- data/lib/generators/doorkeeper/templates/migration.rb.erb +4 -1
- data/spec/controllers/applications_controller_spec.rb +93 -0
- data/spec/controllers/authorizations_controller_spec.rb +143 -62
- data/spec/controllers/protected_resources_controller_spec.rb +3 -3
- data/spec/controllers/tokens_controller_spec.rb +205 -37
- data/spec/dummy/config/application.rb +3 -1
- data/spec/dummy/config/initializers/doorkeeper.rb +54 -9
- data/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb +1 -1
- data/spec/lib/config_spec.rb +43 -1
- data/spec/lib/oauth/authorization_code_request_spec.rb +13 -1
- data/spec/lib/oauth/base_request_spec.rb +33 -16
- data/spec/lib/oauth/client_credentials/creator_spec.rb +3 -0
- data/spec/lib/oauth/code_request_spec.rb +27 -28
- data/spec/lib/oauth/helpers/uri_checker_spec.rb +17 -2
- data/spec/lib/oauth/invalid_request_response_spec.rb +75 -0
- data/spec/lib/oauth/pre_authorization_spec.rb +76 -66
- data/spec/lib/oauth/refresh_token_request_spec.rb +1 -0
- data/spec/lib/oauth/token_request_spec.rb +20 -17
- data/spec/lib/server_spec.rb +0 -12
- data/spec/models/doorkeeper/access_grant_spec.rb +21 -2
- data/spec/models/doorkeeper/access_token_spec.rb +35 -4
- data/spec/models/doorkeeper/application_spec.rb +275 -370
- data/spec/requests/endpoints/authorization_spec.rb +21 -5
- data/spec/requests/endpoints/token_spec.rb +1 -1
- data/spec/requests/flows/authorization_code_errors_spec.rb +1 -0
- data/spec/requests/flows/authorization_code_spec.rb +93 -27
- data/spec/requests/flows/client_credentials_spec.rb +38 -0
- data/spec/requests/flows/implicit_grant_errors_spec.rb +22 -10
- data/spec/requests/flows/implicit_grant_spec.rb +9 -8
- data/spec/requests/flows/password_spec.rb +37 -0
- data/spec/requests/flows/refresh_token_spec.rb +1 -1
- data/spec/requests/flows/revoke_token_spec.rb +19 -11
- data/spec/support/doorkeeper_rspec.rb +1 -1
- data/spec/support/helpers/request_spec_helper.rb +14 -2
- data/spec/validators/redirect_uri_validator_spec.rb +40 -15
- metadata +16 -15
- data/.coveralls.yml +0 -1
- data/.github/ISSUE_TEMPLATE.md +0 -25
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -17
- data/.gitignore +0 -20
- data/.gitlab-ci.yml +0 -16
- data/.hound.yml +0 -3
- data/.rspec +0 -1
- data/.rubocop.yml +0 -50
- data/.travis.yml +0 -35
- data/app/validators/redirect_uri_validator.rb +0 -50
@@ -13,26 +13,27 @@ module Doorkeeper
|
|
13
13
|
|
14
14
|
attr_accessor :access_token, :client, :credentials, :refresh_token,
|
15
15
|
:server
|
16
|
+
attr_reader :missing_param
|
16
17
|
|
17
18
|
def initialize(server, refresh_token, credentials, parameters = {})
|
18
|
-
@server
|
19
|
-
@refresh_token
|
20
|
-
@credentials
|
19
|
+
@server = server
|
20
|
+
@refresh_token = refresh_token
|
21
|
+
@credentials = credentials
|
21
22
|
@original_scopes = parameters[:scope] || parameters[:scopes]
|
22
23
|
@refresh_token_parameter = parameters[:refresh_token]
|
23
|
-
|
24
|
-
if credentials
|
25
|
-
@client = Application.by_uid_and_secret credentials.uid,
|
26
|
-
credentials.secret
|
27
|
-
end
|
24
|
+
@client = load_client(credentials) if credentials
|
28
25
|
end
|
29
26
|
|
30
27
|
private
|
31
28
|
|
29
|
+
def load_client(credentials)
|
30
|
+
Application.by_uid_and_secret(credentials.uid, credentials.secret)
|
31
|
+
end
|
32
|
+
|
32
33
|
def before_successful_response
|
33
34
|
refresh_token.transaction do
|
34
35
|
refresh_token.lock!
|
35
|
-
raise Errors::
|
36
|
+
raise Errors::InvalidGrantReuse if refresh_token.revoked?
|
36
37
|
|
37
38
|
refresh_token.revoke unless refresh_token_revoked_on_use?
|
38
39
|
create_access_token
|
@@ -76,7 +77,9 @@ module Doorkeeper
|
|
76
77
|
end
|
77
78
|
|
78
79
|
def validate_token_presence
|
79
|
-
refresh_token.
|
80
|
+
@missing_param = :refresh_token if refresh_token.blank? && @refresh_token_parameter.blank?
|
81
|
+
|
82
|
+
@missing_param.nil?
|
80
83
|
end
|
81
84
|
|
82
85
|
def validate_token
|
@@ -7,7 +7,7 @@ module Doorkeeper
|
|
7
7
|
# @see https://tools.ietf.org/html/rfc7662
|
8
8
|
class TokenIntrospection
|
9
9
|
attr_reader :server, :token
|
10
|
-
attr_reader :error
|
10
|
+
attr_reader :error, :invalid_request_reason
|
11
11
|
|
12
12
|
def initialize(server, token)
|
13
13
|
@server = server
|
@@ -25,6 +25,8 @@ module Doorkeeper
|
|
25
25
|
|
26
26
|
if @error == :invalid_token
|
27
27
|
OAuth::InvalidTokenResponse.from_access_token(authorized_token)
|
28
|
+
elsif @error == :invalid_request
|
29
|
+
OAuth::InvalidRequestResponse.from_request(self)
|
28
30
|
else
|
29
31
|
OAuth::ErrorResponse.new(name: @error)
|
30
32
|
end
|
@@ -67,9 +69,10 @@ module Doorkeeper
|
|
67
69
|
# HTTP 401 code as described in Section 3 of OAuth 2.0 Bearer Token
|
68
70
|
# Usage [RFC6750].
|
69
71
|
#
|
70
|
-
@error = :invalid_token
|
72
|
+
@error = :invalid_token unless valid_authorized_token?
|
71
73
|
else
|
72
74
|
@error = :invalid_request
|
75
|
+
@invalid_request_reason = :request_not_authorized
|
73
76
|
end
|
74
77
|
end
|
75
78
|
|
@@ -80,8 +83,7 @@ module Doorkeeper
|
|
80
83
|
|
81
84
|
# Bearer Token Authentication
|
82
85
|
def authorized_token
|
83
|
-
@authorized_token ||=
|
84
|
-
OAuth::Token.authenticate(server.context.request, :from_bearer_authorization)
|
86
|
+
@authorized_token ||= Doorkeeper.authenticate(server.context.request)
|
85
87
|
end
|
86
88
|
|
87
89
|
# 2.2. Introspection Response
|
@@ -150,7 +152,7 @@ module Doorkeeper
|
|
150
152
|
#
|
151
153
|
def active?
|
152
154
|
if authorized_client
|
153
|
-
valid_token? &&
|
155
|
+
valid_token? && token_introspection_allowed?(auth_client: authorized_client.application)
|
154
156
|
else
|
155
157
|
valid_token?
|
156
158
|
end
|
@@ -161,19 +163,27 @@ module Doorkeeper
|
|
161
163
|
@token&.accessible?
|
162
164
|
end
|
163
165
|
|
166
|
+
def valid_authorized_token?
|
167
|
+
!authorized_token_matches_introspected? &&
|
168
|
+
authorized_token.accessible? &&
|
169
|
+
token_introspection_allowed?(auth_token: authorized_token)
|
170
|
+
end
|
171
|
+
|
164
172
|
# RFC7662 Section 2.1
|
165
173
|
def authorized_token_matches_introspected?
|
166
174
|
authorized_token.token == @token&.token
|
167
175
|
end
|
168
176
|
|
169
|
-
#
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
+
# config constraints for introspection in Doorkeeper.configuration.allow_token_introspection
|
178
|
+
def token_introspection_allowed?(auth_client: nil, auth_token: nil)
|
179
|
+
allow_introspection = Doorkeeper.configuration.allow_token_introspection
|
180
|
+
return allow_introspection unless allow_introspection.respond_to?(:call)
|
181
|
+
|
182
|
+
allow_introspection.call(
|
183
|
+
@token,
|
184
|
+
auth_client,
|
185
|
+
auth_token
|
186
|
+
)
|
177
187
|
end
|
178
188
|
|
179
189
|
# Allows to customize introspection response.
|
@@ -11,28 +11,14 @@ module Doorkeeper
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def authorize
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@response = CodeResponse.new pre_auth,
|
18
|
-
auth,
|
19
|
-
response_on_fragment: true
|
20
|
-
else
|
21
|
-
@response = error_response
|
22
|
-
end
|
14
|
+
auth = Authorization::Token.new(pre_auth, resource_owner)
|
15
|
+
auth.issue_token
|
16
|
+
CodeResponse.new(pre_auth, auth, response_on_fragment: true)
|
23
17
|
end
|
24
18
|
|
25
19
|
def deny
|
26
20
|
pre_auth.error = :access_denied
|
27
|
-
error_response
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def error_response
|
33
|
-
ErrorResponse.from_request pre_auth,
|
34
|
-
redirect_uri: pre_auth.redirect_uri,
|
35
|
-
response_on_fragment: true
|
21
|
+
pre_auth.error_response
|
36
22
|
end
|
37
23
|
end
|
38
24
|
end
|
@@ -9,8 +9,8 @@ module Doorkeeper
|
|
9
9
|
belongs_to :application, class_name: "Doorkeeper::Application",
|
10
10
|
inverse_of: :access_tokens, optional: true
|
11
11
|
|
12
|
-
validates :token, presence: true, uniqueness: true
|
13
|
-
validates :refresh_token, uniqueness: true, if: :use_refresh_token?
|
12
|
+
validates :token, presence: true, uniqueness: { case_sensitive: true }
|
13
|
+
validates :refresh_token, uniqueness: { case_sensitive: true }, if: :use_refresh_token?
|
14
14
|
|
15
15
|
# @attr_writer [Boolean, nil] use_refresh_token
|
16
16
|
# indicates the possibility of using refresh token
|
@@ -10,8 +10,8 @@ module Doorkeeper
|
|
10
10
|
has_many :access_tokens, dependent: :delete_all, class_name: "Doorkeeper::AccessToken"
|
11
11
|
|
12
12
|
validates :name, :secret, :uid, presence: true
|
13
|
-
validates :uid, uniqueness: true
|
14
|
-
validates :redirect_uri, redirect_uri: true
|
13
|
+
validates :uid, uniqueness: { case_sensitive: true }
|
14
|
+
validates :redirect_uri, "doorkeeper/redirect_uri": true
|
15
15
|
validates :confidential, inclusion: { in: [true, false] }
|
16
16
|
|
17
17
|
validate :scopes_match_configured, if: :enforce_scopes?
|
@@ -46,6 +46,14 @@ module Doorkeeper
|
|
46
46
|
AccessGrant.revoke_all_for(id, resource_owner)
|
47
47
|
end
|
48
48
|
|
49
|
+
# Generates a new secret for this application, intended to be used
|
50
|
+
# for rotating the secret or in case of compromise.
|
51
|
+
#
|
52
|
+
def renew_secret
|
53
|
+
@raw_secret = UniqueToken.generate
|
54
|
+
secret_strategy.store_secret(self, :secret, @raw_secret)
|
55
|
+
end
|
56
|
+
|
49
57
|
# We keep a volatile copy of the raw secret for initial communication
|
50
58
|
# The stored refresh_token may be mapped and not available in cleartext.
|
51
59
|
#
|
@@ -60,38 +68,10 @@ module Doorkeeper
|
|
60
68
|
end
|
61
69
|
end
|
62
70
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
# for public/private clients and full set for authorized owners.
|
68
|
-
#
|
69
|
-
# @return [Hash] entity attributes for JSON
|
70
|
-
#
|
71
|
-
def as_json(options = {})
|
72
|
-
# if application belongs to some owner we need to check if it's the same as
|
73
|
-
# the one passed in the options or check if we render the client as an owner
|
74
|
-
if (respond_to?(:owner) && owner && owner == options[:current_resource_owner]) ||
|
75
|
-
options[:as_owner]
|
76
|
-
# Owners can see all the client attributes, fallback to ActiveModel serialization
|
77
|
-
super
|
78
|
-
else
|
79
|
-
# if application has no owner or it's owner doesn't match one from the options
|
80
|
-
# we render only minimum set of attributes that could be exposed to a public
|
81
|
-
only = extract_serializable_attributes(options)
|
82
|
-
super(options.merge(only: only))
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# We need to hook into this method to allow serializing plan-text secrets
|
87
|
-
# when secrets hashing enabled.
|
88
|
-
#
|
89
|
-
# @param key [String] attribute name
|
90
|
-
#
|
91
|
-
def read_attribute_for_serialization(key)
|
92
|
-
return super unless key.to_s == "secret"
|
93
|
-
|
94
|
-
plaintext_secret || secret
|
71
|
+
def to_json(options = nil)
|
72
|
+
serializable_hash(except: :secret)
|
73
|
+
.merge(secret: plaintext_secret)
|
74
|
+
.to_json(options)
|
95
75
|
end
|
96
76
|
|
97
77
|
private
|
@@ -102,9 +82,7 @@ module Doorkeeper
|
|
102
82
|
|
103
83
|
def generate_secret
|
104
84
|
return unless secret.blank?
|
105
|
-
|
106
|
-
@raw_secret = UniqueToken.generate
|
107
|
-
secret_strategy.store_secret(self, :secret, @raw_secret)
|
85
|
+
renew_secret
|
108
86
|
end
|
109
87
|
|
110
88
|
def scopes_match_configured
|
@@ -118,37 +96,5 @@ module Doorkeeper
|
|
118
96
|
def enforce_scopes?
|
119
97
|
Doorkeeper.configuration.enforce_configured_scopes?
|
120
98
|
end
|
121
|
-
|
122
|
-
# Helper method to extract collection of serializable attribute names
|
123
|
-
# considering serialization options (like `only`, `except` and so on).
|
124
|
-
#
|
125
|
-
# @param options [Hash] serialization options
|
126
|
-
#
|
127
|
-
# @return [Array<String>]
|
128
|
-
# collection of attributes to be serialized using #as_json
|
129
|
-
#
|
130
|
-
def extract_serializable_attributes(options = {})
|
131
|
-
opts = options.try(:dup) || {}
|
132
|
-
only = Array.wrap(opts[:only]).map(&:to_s)
|
133
|
-
|
134
|
-
only = if only.blank?
|
135
|
-
serializable_attributes
|
136
|
-
else
|
137
|
-
only & serializable_attributes
|
138
|
-
end
|
139
|
-
|
140
|
-
only -= Array.wrap(opts[:except]).map(&:to_s) if opts.key?(:except)
|
141
|
-
only.uniq
|
142
|
-
end
|
143
|
-
|
144
|
-
# Collection of attributes that could be serialized for public.
|
145
|
-
# Override this method if you need additional attributes to be serialized.
|
146
|
-
#
|
147
|
-
# @return [Array<String>] collection of serializable attributes
|
148
|
-
def serializable_attributes
|
149
|
-
attributes = %w[id name created_at]
|
150
|
-
attributes << "uid" unless confidential?
|
151
|
-
attributes
|
152
|
-
end
|
153
99
|
end
|
154
100
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
module Doorkeeper
|
6
|
+
# ActiveModel validator for redirect URI validation in according
|
7
|
+
# to OAuth standards and Doorkeeper configuration.
|
8
|
+
class RedirectUriValidator < ActiveModel::EachValidator
|
9
|
+
def validate_each(record, attribute, value)
|
10
|
+
if value.blank?
|
11
|
+
return if Doorkeeper.configuration.allow_blank_redirect_uri?(record)
|
12
|
+
|
13
|
+
record.errors.add(attribute, :blank)
|
14
|
+
else
|
15
|
+
value.split.each do |val|
|
16
|
+
next if oob_redirect_uri?(val)
|
17
|
+
|
18
|
+
uri = ::URI.parse(val)
|
19
|
+
record.errors.add(attribute, :forbidden_uri) if forbidden_uri?(uri)
|
20
|
+
record.errors.add(attribute, :fragment_present) unless uri.fragment.nil?
|
21
|
+
record.errors.add(attribute, :unspecified_scheme) if unspecified_scheme?(uri)
|
22
|
+
record.errors.add(attribute, :relative_uri) if relative_uri?(uri)
|
23
|
+
record.errors.add(attribute, :secured_uri) if invalid_ssl_uri?(uri)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
rescue URI::InvalidURIError
|
27
|
+
record.errors.add(attribute, :invalid_uri)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def oob_redirect_uri?(uri)
|
33
|
+
Doorkeeper::OAuth::NonStandard::IETF_WG_OAUTH2_OOB_METHODS.include?(uri)
|
34
|
+
end
|
35
|
+
|
36
|
+
def forbidden_uri?(uri)
|
37
|
+
Doorkeeper.configuration.forbid_redirect_uri.call(uri)
|
38
|
+
end
|
39
|
+
|
40
|
+
def unspecified_scheme?(uri)
|
41
|
+
return true if uri.opaque.present?
|
42
|
+
|
43
|
+
%w[localhost].include?(uri.try(:scheme))
|
44
|
+
end
|
45
|
+
|
46
|
+
def relative_uri?(uri)
|
47
|
+
uri.scheme.nil? && uri.host.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
def invalid_ssl_uri?(uri)
|
51
|
+
forces_ssl = Doorkeeper.configuration.force_ssl_in_redirect_uri
|
52
|
+
non_https = uri.try(:scheme) == "http"
|
53
|
+
|
54
|
+
if forces_ssl.respond_to?(:call)
|
55
|
+
forces_ssl.call(uri) && non_https
|
56
|
+
else
|
57
|
+
forces_ssl && non_https
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -2,19 +2,27 @@
|
|
2
2
|
|
3
3
|
require "active_support/lazy_load_hooks"
|
4
4
|
|
5
|
-
require "doorkeeper/orm/active_record/stale_records_cleaner"
|
6
|
-
|
7
5
|
module Doorkeeper
|
8
6
|
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
|
+
#
|
9
15
|
module ActiveRecord
|
10
16
|
def self.initialize_models!
|
11
17
|
lazy_load do
|
18
|
+
require "doorkeeper/orm/active_record/stale_records_cleaner"
|
19
|
+
require "doorkeeper/orm/active_record/redirect_uri_validator"
|
12
20
|
require "doorkeeper/orm/active_record/access_grant"
|
13
21
|
require "doorkeeper/orm/active_record/access_token"
|
14
22
|
require "doorkeeper/orm/active_record/application"
|
15
23
|
|
16
24
|
if Doorkeeper.configuration.active_record_options[:establish_connection]
|
17
|
-
|
25
|
+
Doorkeeper::Orm::ActiveRecord.models.each do |model|
|
18
26
|
options = Doorkeeper.configuration.active_record_options[:establish_connection]
|
19
27
|
model.establish_connection(options)
|
20
28
|
end
|
@@ -33,6 +41,14 @@ module Doorkeeper
|
|
33
41
|
def self.lazy_load(&block)
|
34
42
|
ActiveSupport.on_load(:active_record, {}, &block)
|
35
43
|
end
|
44
|
+
|
45
|
+
def self.models
|
46
|
+
[
|
47
|
+
Doorkeeper::AccessGrant,
|
48
|
+
Doorkeeper::AccessToken,
|
49
|
+
Doorkeeper::Application,
|
50
|
+
]
|
51
|
+
end
|
36
52
|
end
|
37
53
|
end
|
38
54
|
end
|
data/lib/doorkeeper/request.rb
CHANGED
@@ -4,30 +4,25 @@ module Doorkeeper
|
|
4
4
|
module Request
|
5
5
|
class << self
|
6
6
|
def authorization_strategy(response_type)
|
7
|
-
|
8
|
-
rescue NameError
|
9
|
-
raise Errors::InvalidAuthorizationStrategy
|
7
|
+
build_strategy_class(response_type)
|
10
8
|
end
|
11
9
|
|
12
10
|
def token_strategy(grant_type)
|
11
|
+
raise Errors::MissingRequiredParameter, :grant_type if grant_type.blank?
|
12
|
+
|
13
13
|
get_strategy(grant_type, token_grant_types)
|
14
14
|
rescue NameError
|
15
15
|
raise Errors::InvalidTokenStrategy
|
16
16
|
end
|
17
17
|
|
18
|
-
def get_strategy(
|
19
|
-
raise
|
20
|
-
raise NameError unless available.include?(grant_or_request_type.to_s)
|
18
|
+
def get_strategy(grant_type, available)
|
19
|
+
raise NameError unless available.include?(grant_type.to_s)
|
21
20
|
|
22
|
-
build_strategy_class(
|
21
|
+
build_strategy_class(grant_type)
|
23
22
|
end
|
24
23
|
|
25
24
|
private
|
26
25
|
|
27
|
-
def authorization_response_types
|
28
|
-
Doorkeeper.configuration.authorization_response_types
|
29
|
-
end
|
30
|
-
|
31
26
|
def token_grant_types
|
32
27
|
Doorkeeper.configuration.token_grant_types
|
33
28
|
end
|
data/lib/doorkeeper/server.rb
CHANGED
@@ -10,12 +10,12 @@ module Doorkeeper
|
|
10
10
|
|
11
11
|
def authorization_request(strategy)
|
12
12
|
klass = Request.authorization_strategy strategy
|
13
|
-
klass.new
|
13
|
+
klass.new(self)
|
14
14
|
end
|
15
15
|
|
16
16
|
def token_request(strategy)
|
17
17
|
klass = Request.token_strategy strategy
|
18
|
-
klass.new
|
18
|
+
klass.new(self)
|
19
19
|
end
|
20
20
|
|
21
21
|
# TODO: context should be the request
|
@@ -27,10 +27,6 @@ module Doorkeeper
|
|
27
27
|
@client ||= OAuth::Client.authenticate(credentials)
|
28
28
|
end
|
29
29
|
|
30
|
-
def client_via_uid
|
31
|
-
@client_via_uid ||= OAuth::Client.find(parameters[:client_id])
|
32
|
-
end
|
33
|
-
|
34
30
|
def current_resource_owner
|
35
31
|
context.send :current_resource_owner
|
36
32
|
end
|
@@ -5,12 +5,16 @@ module Doorkeeper
|
|
5
5
|
CLEANER_CLASS = "StaleRecordsCleaner"
|
6
6
|
|
7
7
|
def self.for(base_scope)
|
8
|
-
orm_adapter = "doorkeeper/orm/#{
|
8
|
+
orm_adapter = "doorkeeper/orm/#{configured_orm}".classify
|
9
9
|
|
10
10
|
orm_cleaner = "#{orm_adapter}::#{CLEANER_CLASS}".constantize
|
11
11
|
orm_cleaner.new(base_scope)
|
12
12
|
rescue NameError
|
13
|
-
raise Doorkeeper::Errors::NoOrmCleaner, "'#{
|
13
|
+
raise Doorkeeper::Errors::NoOrmCleaner, "'#{configured_orm}' ORM has no cleaner!"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configured_orm
|
17
|
+
Doorkeeper.configuration.orm
|
14
18
|
end
|
15
19
|
|
16
20
|
def self.new(base_scope)
|
data/lib/doorkeeper/version.rb
CHANGED
data/lib/doorkeeper.rb
CHANGED
@@ -52,6 +52,8 @@ require "doorkeeper/oauth/token"
|
|
52
52
|
require "doorkeeper/oauth/token_introspection"
|
53
53
|
require "doorkeeper/oauth/invalid_token_response"
|
54
54
|
require "doorkeeper/oauth/forbidden_token_response"
|
55
|
+
require "doorkeeper/oauth/invalid_request_response"
|
56
|
+
require "doorkeeper/oauth/nonstandard"
|
55
57
|
|
56
58
|
require "doorkeeper/secret_storing/base"
|
57
59
|
require "doorkeeper/secret_storing/plain"
|
@@ -80,6 +82,8 @@ require "doorkeeper/stale_records_cleaner"
|
|
80
82
|
|
81
83
|
require "doorkeeper/orm/active_record"
|
82
84
|
|
85
|
+
# Main Doorkeeper namespace.
|
86
|
+
#
|
83
87
|
module Doorkeeper
|
84
88
|
def self.authenticate(request, methods = Doorkeeper.configuration.access_token_methods)
|
85
89
|
OAuth::Token.authenticate(request, *methods)
|
@@ -17,12 +17,12 @@ module Doorkeeper
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def previous_refresh_token
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
return unless no_previous_refresh_token_column?
|
21
|
+
|
22
|
+
migration_template(
|
23
|
+
"add_previous_refresh_token_to_access_tokens.rb.erb",
|
24
|
+
"db/migrate/add_previous_refresh_token_to_access_tokens.rb"
|
25
|
+
)
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|