doorkeeper 5.9.5 → 6.0.0.beta1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +39 -6
- data/README.md +1 -0
- data/app/controllers/doorkeeper/metadata_controller.rb +20 -0
- data/app/controllers/doorkeeper/tokens_controller.rb +10 -1
- data/app/views/doorkeeper/authorizations/new.html.erb +6 -0
- data/lib/doorkeeper/client_authentication/credentials.rb +11 -0
- data/lib/doorkeeper/client_authentication/fallback_method.rb +19 -0
- data/lib/doorkeeper/client_authentication/legacy_callable.rb +46 -0
- data/lib/doorkeeper/client_authentication/method.rb +23 -0
- data/lib/doorkeeper/client_authentication/registry.rb +47 -0
- data/lib/doorkeeper/client_authentication.rb +93 -0
- data/lib/doorkeeper/config/option.rb +1 -1
- data/lib/doorkeeper/config/validations.rb +162 -1
- data/lib/doorkeeper/config.rb +114 -9
- data/lib/doorkeeper/errors.rb +1 -0
- data/lib/doorkeeper/models/access_token_mixin.rb +40 -5
- data/lib/doorkeeper/models/application_mixin.rb +14 -6
- data/lib/doorkeeper/models/concerns/secret_storable.rb +10 -1
- data/lib/doorkeeper/oauth/authorization/uri_builder.rb +11 -0
- data/lib/doorkeeper/oauth/authorization_code_request.rb +4 -1
- data/lib/doorkeeper/oauth/client.rb +18 -0
- data/lib/doorkeeper/oauth/client_authentication/client_secret_basic.rb +53 -0
- data/lib/doorkeeper/oauth/client_authentication/client_secret_post.rb +29 -0
- data/lib/doorkeeper/oauth/client_authentication/none.rb +32 -0
- data/lib/doorkeeper/oauth/code_response.rb +16 -2
- data/lib/doorkeeper/oauth/error_response.rb +11 -2
- data/lib/doorkeeper/oauth/metadata_response.rb +157 -0
- data/lib/doorkeeper/oauth/pre_authorization.rb +12 -5
- data/lib/doorkeeper/oauth/token_introspection.rb +27 -7
- data/lib/doorkeeper/orm/active_record/mixins/application.rb +2 -2
- data/lib/doorkeeper/rails/routes/mapping.rb +1 -0
- data/lib/doorkeeper/rails/routes.rb +6 -0
- data/lib/doorkeeper/request.rb +59 -0
- data/lib/doorkeeper/server.rb +5 -2
- data/lib/doorkeeper/version.rb +4 -4
- data/lib/doorkeeper.rb +8 -4
- data/lib/generators/doorkeeper/templates/initializer.rb +66 -6
- metadata +14 -8
- data/lib/doorkeeper/oauth/client/credentials.rb +0 -71
- data/lib/doorkeeper/oauth/stateless_token.rb +0 -139
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Doorkeeper
|
|
4
|
-
module OAuth
|
|
5
|
-
class Client
|
|
6
|
-
Credentials = Struct.new(:uid, :secret) do
|
|
7
|
-
class << self
|
|
8
|
-
# Extracts the client credentials from the request using the
|
|
9
|
-
# configured extraction methods. The first method that yields
|
|
10
|
-
# credentials wins, as it always has.
|
|
11
|
-
#
|
|
12
|
-
# Raises Errors::MultipleClientAuthMethods when the request
|
|
13
|
-
# authenticates the client with more than one method, which RFC 6749
|
|
14
|
-
# §2.3 forbids ("The client MUST NOT use more than one authentication
|
|
15
|
-
# method in each request").
|
|
16
|
-
def from_request(request, *credentials_methods)
|
|
17
|
-
# Callable extractors are opaque: they may legitimately overlap the
|
|
18
|
-
# built-in methods they are configured with, and evaluating all of
|
|
19
|
-
# them would also break the existing contract that the extractors
|
|
20
|
-
# after the matching one are not called. Such configurations keep
|
|
21
|
-
# the historical behaviour untouched.
|
|
22
|
-
return first_from_request(request, credentials_methods) unless credentials_methods.all?(Symbol)
|
|
23
|
-
|
|
24
|
-
credentials = credentials_methods.filter_map { |method| extract(request, method) }
|
|
25
|
-
|
|
26
|
-
# Only credentials carrying a secret authenticate the client. A bare
|
|
27
|
-
# uid is a public client identifying itself (RFC 6749 §2.3 "none"),
|
|
28
|
-
# not an authentication method of its own, so it doesn't count
|
|
29
|
-
# towards the single-method rule — RFC 7521 §4.2, for example,
|
|
30
|
-
# explicitly allows a client_id next to another authentication
|
|
31
|
-
# method.
|
|
32
|
-
raise Errors::MultipleClientAuthMethods if credentials.count { |c| c.secret.present? } > 1
|
|
33
|
-
|
|
34
|
-
credentials.first
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def from_params(request)
|
|
38
|
-
request.parameters.values_at(:client_id, :client_secret)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def from_basic(request)
|
|
42
|
-
authorization = request.authorization
|
|
43
|
-
if authorization.present? && authorization =~ /^Basic (.*)/im
|
|
44
|
-
Base64.decode64(Regexp.last_match(1)).split(/:/, 2)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
private
|
|
49
|
-
|
|
50
|
-
def first_from_request(request, credentials_methods)
|
|
51
|
-
credentials_methods.inject(nil) do |_, method|
|
|
52
|
-
credentials = extract(request, method)
|
|
53
|
-
break credentials if credentials
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# Returns the credentials the given method extracts from the request,
|
|
58
|
-
# or nil when it extracts none.
|
|
59
|
-
def extract(request, method)
|
|
60
|
-
method = self.method(method) if method.is_a?(Symbol)
|
|
61
|
-
Credentials.new(*method.call(request)).presence
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# Public clients may have their secret blank, but "credentials" are
|
|
66
|
-
# still present
|
|
67
|
-
delegate :blank?, to: :uid
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Doorkeeper
|
|
4
|
-
module OAuth
|
|
5
|
-
# In-memory representation of a verified JWT access token. Returned by
|
|
6
|
-
# OAuth::Token.authenticate when stateless_jwt_tokens is enabled, so that
|
|
7
|
-
# the existing doorkeeper_token / doorkeeper_authorize! helpers work
|
|
8
|
-
# without any database read.
|
|
9
|
-
#
|
|
10
|
-
# Stateless tokens cannot be revoked or refreshed server-side: #revoked?
|
|
11
|
-
# is always false and #revoke is a no-op. Rely on short token lifetimes
|
|
12
|
-
# (access_token_expires_in) for early invalidation.
|
|
13
|
-
class StatelessToken
|
|
14
|
-
attr_reader :claims, :application, :raw_token
|
|
15
|
-
|
|
16
|
-
def initialize(claims:, application: nil, raw_token: nil)
|
|
17
|
-
@claims = claims
|
|
18
|
-
@application = application
|
|
19
|
-
@raw_token = raw_token
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def token_type
|
|
23
|
-
"Bearer"
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# The raw token string. Used by introspection's
|
|
27
|
-
# authorized_token_matches_introspected? security check.
|
|
28
|
-
def token
|
|
29
|
-
@raw_token
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# Issuance path: the freshly-signed JWT returned to the client.
|
|
33
|
-
def plaintext_token
|
|
34
|
-
@raw_token
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def plaintext_refresh_token
|
|
38
|
-
nil
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def resource_owner_id
|
|
42
|
-
claims["resource_owner_id"] || claims["sub"]
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def application_id
|
|
46
|
-
application&.id
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def scopes_string
|
|
50
|
-
claims["scope"].to_s
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def scopes
|
|
54
|
-
OAuth::Scopes.from_string(scopes_string)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def includes_scope?(*required_scopes)
|
|
58
|
-
required_scopes.blank? || required_scopes.any? { |scope| scopes.exists?(scope.to_s) }
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def custom_attributes
|
|
62
|
-
claims.slice(*Doorkeeper.config.custom_access_token_attributes.map(&:to_s))
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# RFC 8707 resource indicator. Stored as a space-delimited string to
|
|
66
|
-
# match the AccessToken column shape consumed by token_introspection.
|
|
67
|
-
def resource
|
|
68
|
-
aud = claims["aud"]
|
|
69
|
-
return nil if aud.blank?
|
|
70
|
-
|
|
71
|
-
aud.is_a?(Array) ? aud.join(" ") : aud.to_s
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def created_at
|
|
75
|
-
Time.at(claims["iat"].to_i).utc
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def expires_in
|
|
79
|
-
claims["expires_in"]
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def expires_at
|
|
83
|
-
return nil unless claims["exp"]
|
|
84
|
-
|
|
85
|
-
Time.at(claims["exp"].to_i).utc
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def expires_in_seconds
|
|
89
|
-
return nil unless expires_at
|
|
90
|
-
|
|
91
|
-
expires = expires_at - Time.now.utc
|
|
92
|
-
sec = expires.seconds.round(0)
|
|
93
|
-
sec > 0 ? sec : 0
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def expired?
|
|
97
|
-
return false unless expires_at
|
|
98
|
-
|
|
99
|
-
Time.now.utc > expires_at
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def revoked?
|
|
103
|
-
false
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def accessible?
|
|
107
|
-
!expired? && !revoked?
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def acceptable?(required_scopes)
|
|
111
|
-
accessible? && includes_scope?(*required_scopes)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
def revoke_previous_refresh_token!
|
|
115
|
-
# no-op: stateless tokens carry no refresh-token chain to revoke.
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def revoke
|
|
119
|
-
# no-op: stateless tokens cannot be revoked server-side.
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def revocable?
|
|
123
|
-
false
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
def as_json(_options = {})
|
|
127
|
-
{
|
|
128
|
-
resource_owner_id: resource_owner_id,
|
|
129
|
-
scope: scopes,
|
|
130
|
-
expires_in: expires_in_seconds,
|
|
131
|
-
application: { uid: application.try(:uid) },
|
|
132
|
-
created_at: created_at.to_i,
|
|
133
|
-
}.tap do |json|
|
|
134
|
-
json[:resource_owner_type] = claims["resource_owner_type"] if Doorkeeper.configuration.polymorphic_resource_owner?
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
end
|