doorkeeper 5.9.6 → 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 +43 -7
- 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 +113 -12
- 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 +65 -13
- metadata +14 -7
- data/lib/doorkeeper/oauth/client/credentials.rb +0 -86
|
@@ -1,86 +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, or presents
|
|
14
|
-
# more than one client identity, which RFC 6749 §2.3 forbids ("The
|
|
15
|
-
# client MUST NOT use more than one authentication method in each
|
|
16
|
-
# request").
|
|
17
|
-
def from_request(request, *credentials_methods)
|
|
18
|
-
# Callable extractors are opaque: they may legitimately overlap the
|
|
19
|
-
# built-in methods they are configured with, and evaluating all of
|
|
20
|
-
# them would also break the existing contract that the extractors
|
|
21
|
-
# after the matching one are not called. Such configurations keep
|
|
22
|
-
# the historical behaviour untouched, including the fact that a
|
|
23
|
-
# request authenticating with more than one method, or presenting
|
|
24
|
-
# more than one client identity, resolves to the first extracted
|
|
25
|
-
# credentials instead of being rejected: the extractor that would
|
|
26
|
-
# have surfaced the second identity is never evaluated. The
|
|
27
|
-
# +client_credentials+ configuration option documents this.
|
|
28
|
-
return first_from_request(request, credentials_methods) unless credentials_methods.all?(Symbol)
|
|
29
|
-
|
|
30
|
-
credentials = credentials_methods.filter_map { |method| extract(request, method) }
|
|
31
|
-
|
|
32
|
-
# Only credentials carrying a secret authenticate the client. A bare
|
|
33
|
-
# uid is a public client identifying itself (RFC 6749 §2.3 "none"),
|
|
34
|
-
# not an authentication method of its own, so it doesn't count
|
|
35
|
-
# towards the single-method rule — RFC 7521 §4.2, for example,
|
|
36
|
-
# explicitly allows a client_id next to another authentication
|
|
37
|
-
# method.
|
|
38
|
-
raise Errors::MultipleClientAuthMethods if credentials.count { |c| c.secret.present? } > 1
|
|
39
|
-
|
|
40
|
-
# §4.2 allows that bare client_id because it identifies the *same*
|
|
41
|
-
# client as the authentication method it accompanies. Credentials
|
|
42
|
-
# naming two different clients are two client identities in one
|
|
43
|
-
# request and authenticate neither: without this check the first
|
|
44
|
-
# extracted uid would win and the other identity would be silently
|
|
45
|
-
# discarded, so the caller could authenticate as one client while
|
|
46
|
-
# the request asks to act as another.
|
|
47
|
-
raise Errors::MultipleClientAuthMethods if credentials.uniq(&:uid).size > 1
|
|
48
|
-
|
|
49
|
-
credentials.first
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def from_params(request)
|
|
53
|
-
request.parameters.values_at(:client_id, :client_secret)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def from_basic(request)
|
|
57
|
-
authorization = request.authorization
|
|
58
|
-
if authorization.present? && authorization =~ /^Basic (.*)/im
|
|
59
|
-
Base64.decode64(Regexp.last_match(1)).split(/:/, 2)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
private
|
|
64
|
-
|
|
65
|
-
def first_from_request(request, credentials_methods)
|
|
66
|
-
credentials_methods.inject(nil) do |_, method|
|
|
67
|
-
credentials = extract(request, method)
|
|
68
|
-
break credentials if credentials
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
# Returns the credentials the given method extracts from the request,
|
|
73
|
-
# or nil when it extracts none.
|
|
74
|
-
def extract(request, method)
|
|
75
|
-
method = self.method(method) if method.is_a?(Symbol)
|
|
76
|
-
Credentials.new(*method.call(request)).presence
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
# Public clients may have their secret blank, but "credentials" are
|
|
81
|
-
# still present
|
|
82
|
-
delegate :blank?, to: :uid
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|