oauth2 1.4.7 → 2.0.20
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
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +811 -76
- data/CITATION.cff +20 -0
- data/CODE_OF_CONDUCT.md +24 -23
- data/CONTRIBUTING.md +221 -0
- data/FUNDING.md +74 -0
- data/IRP.md +107 -0
- data/{LICENSE → LICENSE.txt} +2 -2
- data/OIDC.md +167 -0
- data/README.md +1468 -166
- data/REEK +2 -0
- data/RUBOCOP.md +71 -0
- data/SECURITY.md +24 -0
- data/THREAT_MODEL.md +94 -0
- data/lib/oauth2/access_token.rb +276 -40
- data/lib/oauth2/auth_sanitizer.rb +36 -0
- data/lib/oauth2/authenticator.rb +51 -10
- data/lib/oauth2/client.rb +444 -124
- data/lib/oauth2/error.rb +63 -24
- data/lib/oauth2/filtered_attributes.rb +10 -0
- data/lib/oauth2/response.rb +138 -43
- data/lib/oauth2/strategy/assertion.rb +71 -41
- data/lib/oauth2/strategy/auth_code.rb +28 -5
- data/lib/oauth2/strategy/base.rb +2 -0
- data/lib/oauth2/strategy/client_credentials.rb +6 -4
- data/lib/oauth2/strategy/implicit.rb +20 -3
- data/lib/oauth2/strategy/password.rb +17 -5
- data/lib/oauth2/version.rb +2 -59
- data/lib/oauth2.rb +103 -12
- data/sig/oauth2/access_token.rbs +25 -0
- data/sig/oauth2/authenticator.rbs +22 -0
- data/sig/oauth2/client.rbs +52 -0
- data/sig/oauth2/error.rbs +8 -0
- data/sig/oauth2/filtered_attributes.rbs +11 -0
- data/sig/oauth2/response.rbs +18 -0
- data/sig/oauth2/sanitized_logger.rbs +32 -0
- data/sig/oauth2/strategy.rbs +34 -0
- data/sig/oauth2/thing_filter.rbs +10 -0
- data/sig/oauth2/version.rbs +5 -0
- data/sig/oauth2.rbs +9 -0
- data.tar.gz.sig +0 -0
- metadata +293 -102
- metadata.gz.sig +4 -0
- data/lib/oauth2/mac_token.rb +0 -130
- data/spec/helper.rb +0 -37
- data/spec/oauth2/access_token_spec.rb +0 -216
- data/spec/oauth2/authenticator_spec.rb +0 -84
- data/spec/oauth2/client_spec.rb +0 -506
- data/spec/oauth2/mac_token_spec.rb +0 -117
- data/spec/oauth2/response_spec.rb +0 -90
- data/spec/oauth2/strategy/assertion_spec.rb +0 -58
- data/spec/oauth2/strategy/auth_code_spec.rb +0 -107
- data/spec/oauth2/strategy/base_spec.rb +0 -5
- data/spec/oauth2/strategy/client_credentials_spec.rb +0 -69
- data/spec/oauth2/strategy/implicit_spec.rb +0 -26
- data/spec/oauth2/strategy/password_spec.rb +0 -55
- data/spec/oauth2/version_spec.rb +0 -23
data/lib/oauth2/authenticator.rb
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "base64"
|
|
2
4
|
|
|
3
5
|
module OAuth2
|
|
6
|
+
# Builds and applies client authentication to token and revoke requests.
|
|
7
|
+
#
|
|
8
|
+
# Depending on the selected mode, credentials are applied as Basic Auth
|
|
9
|
+
# headers, request body parameters, or only the client_id is sent (TLS).
|
|
4
10
|
class Authenticator
|
|
11
|
+
include FilteredAttributes
|
|
12
|
+
|
|
13
|
+
# @return [Symbol, String] Authentication mode (e.g., :basic_auth, :request_body, :tls_client_auth, :private_key_jwt)
|
|
14
|
+
# @return [String, nil] Client identifier
|
|
15
|
+
# @return [String, nil] Client secret (filtered in inspected output)
|
|
5
16
|
attr_reader :mode, :id, :secret
|
|
17
|
+
filtered_attributes :secret
|
|
6
18
|
|
|
19
|
+
# Create a new Authenticator
|
|
20
|
+
#
|
|
21
|
+
# @param [String, nil] id Client identifier
|
|
22
|
+
# @param [String, nil] secret Client secret
|
|
23
|
+
# @param [Symbol, String] mode Authentication mode
|
|
7
24
|
def initialize(id, secret, mode)
|
|
8
25
|
@id = id
|
|
9
26
|
@secret = secret
|
|
@@ -12,7 +29,7 @@ module OAuth2
|
|
|
12
29
|
|
|
13
30
|
# Apply the request credentials used to authenticate to the Authorization Server
|
|
14
31
|
#
|
|
15
|
-
# Depending on configuration, this might be as request params or as an
|
|
32
|
+
# Depending on the configuration, this might be as request params or as an
|
|
16
33
|
# Authorization header.
|
|
17
34
|
#
|
|
18
35
|
# User-provided params and header take precedence.
|
|
@@ -34,35 +51,59 @@ module OAuth2
|
|
|
34
51
|
end
|
|
35
52
|
end
|
|
36
53
|
|
|
37
|
-
|
|
38
|
-
|
|
54
|
+
class << self
|
|
55
|
+
# Encodes a Basic Authorization header value for the provided credentials.
|
|
56
|
+
#
|
|
57
|
+
# @param [String] user The client identifier
|
|
58
|
+
# @param [String] password The client secret
|
|
59
|
+
# @return [String] The value to use for the Authorization header
|
|
60
|
+
def encode_basic_auth(user, password)
|
|
61
|
+
"Basic #{Base64.strict_encode64("#{user}:#{password}")}"
|
|
62
|
+
end
|
|
39
63
|
end
|
|
40
64
|
|
|
41
65
|
private
|
|
42
66
|
|
|
43
67
|
# Adds client_id and client_secret request parameters if they are not
|
|
44
68
|
# already set.
|
|
69
|
+
#
|
|
70
|
+
# @param [Hash] params Request parameters
|
|
71
|
+
# @return [Hash] Updated parameters including client_id and client_secret
|
|
45
72
|
def apply_params_auth(params)
|
|
46
|
-
|
|
73
|
+
result = {}
|
|
74
|
+
result["client_id"] = id unless id.nil?
|
|
75
|
+
result["client_secret"] = secret unless secret.nil?
|
|
76
|
+
result.merge(params)
|
|
47
77
|
end
|
|
48
78
|
|
|
49
|
-
# When using schemes that don't require the client_secret to be passed
|
|
79
|
+
# When using schemes that don't require the client_secret to be passed (e.g., TLS Client Auth),
|
|
50
80
|
# we don't want to send the secret
|
|
81
|
+
#
|
|
82
|
+
# @param [Hash] params Request parameters
|
|
83
|
+
# @return [Hash] Updated parameters including only client_id
|
|
51
84
|
def apply_client_id(params)
|
|
52
|
-
|
|
85
|
+
result = {}
|
|
86
|
+
result["client_id"] = id unless id.nil?
|
|
87
|
+
result.merge(params)
|
|
53
88
|
end
|
|
54
89
|
|
|
55
90
|
# Adds an `Authorization` header with Basic Auth credentials if and only if
|
|
56
91
|
# it is not already set in the params.
|
|
92
|
+
#
|
|
93
|
+
# @param [Hash] params Request parameters (may include :headers)
|
|
94
|
+
# @return [Hash] Updated parameters with Authorization header
|
|
57
95
|
def apply_basic_auth(params)
|
|
58
96
|
headers = params.fetch(:headers, {})
|
|
59
97
|
headers = basic_auth_header.merge(headers)
|
|
60
|
-
params.merge(:
|
|
98
|
+
params.merge(headers: headers)
|
|
61
99
|
end
|
|
62
100
|
|
|
63
|
-
#
|
|
101
|
+
# Build the Basic Authorization header.
|
|
102
|
+
#
|
|
103
|
+
# @see https://datatracker.ietf.org/doc/html/rfc2617#section-2
|
|
104
|
+
# @return [Hash] Header hash containing the Authorization entry
|
|
64
105
|
def basic_auth_header
|
|
65
|
-
{
|
|
106
|
+
{"Authorization" => self.class.encode_basic_auth(id, secret)}
|
|
66
107
|
end
|
|
67
108
|
end
|
|
68
109
|
end
|