omniauth_oidc 0.2.7 → 1.1.0
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/.rubocop.yml +2 -1
- data/CHANGELOG.md +115 -0
- data/LICENSE.txt +1 -1
- data/README.md +157 -69
- data/lib/omniauth/oidc/client.rb +86 -0
- data/lib/omniauth/oidc/config_fetcher.rb +114 -0
- data/lib/omniauth/oidc/errors.rb +20 -1
- data/lib/omniauth/oidc/http_client.rb +103 -0
- data/lib/omniauth/oidc/jwk_handler.rb +48 -0
- data/lib/omniauth/oidc/jwks_cache.rb +30 -0
- data/lib/omniauth/oidc/logging.rb +76 -0
- data/lib/omniauth/oidc/response_objects.rb +176 -0
- data/lib/omniauth/oidc/ttl_cache.rb +82 -0
- data/lib/omniauth/oidc/version.rb +1 -1
- data/lib/omniauth/strategies/oidc/callback.rb +137 -90
- data/lib/omniauth/strategies/oidc/request.rb +22 -18
- data/lib/omniauth/strategies/oidc/verify.rb +172 -68
- data/lib/omniauth/strategies/oidc.rb +93 -34
- data/lib/omniauth_oidc.rb +8 -0
- data/omniauth_oidc.gemspec +8 -5
- data/sig/omniauth_oidc.rbs +214 -1
- metadata +45 -34
|
@@ -5,6 +5,15 @@ module OmniAuth
|
|
|
5
5
|
class Oidc
|
|
6
6
|
# Token verification phase
|
|
7
7
|
module Verify # rubocop:disable Metrics/ModuleLength
|
|
8
|
+
HMAC_ALGORITHMS = %w[HS256 HS384 HS512].freeze
|
|
9
|
+
|
|
10
|
+
# Algorithm assumed when neither client_signing_alg nor the discovery document names one
|
|
11
|
+
DEFAULT_SIGNING_ALGORITHM = "RS256"
|
|
12
|
+
|
|
13
|
+
# Minimum seconds between JWKS refreshes triggered by an unknown kid, so tokens with
|
|
14
|
+
# made-up kids cannot be used to hammer the provider's JWKS endpoint.
|
|
15
|
+
JWKS_REFRESH_MIN_INTERVAL = 60
|
|
16
|
+
|
|
8
17
|
def secret
|
|
9
18
|
base64_decoded_jwt_secret || client_options.secret
|
|
10
19
|
end
|
|
@@ -27,10 +36,28 @@ module OmniAuth
|
|
|
27
36
|
end
|
|
28
37
|
end
|
|
29
38
|
|
|
39
|
+
# Refetch the JWKS, at most once per JWKS_REFRESH_MIN_INTERVAL for each jwks_uri
|
|
40
|
+
def public_key_with_refresh
|
|
41
|
+
return public_key if configured_public_key || config.jwks_uri.nil?
|
|
42
|
+
|
|
43
|
+
OmniauthOidc::Logging.info("Refreshing JWKS", jwks_uri: config.jwks_uri)
|
|
44
|
+
@public_key = fetch_key(force_refresh: true)
|
|
45
|
+
end
|
|
46
|
+
|
|
30
47
|
private
|
|
31
48
|
|
|
32
|
-
def fetch_key
|
|
33
|
-
|
|
49
|
+
def fetch_key(force_refresh: false)
|
|
50
|
+
OmniauthOidc::JwksCache.instance.fetch(config.jwks_uri, force_refresh: force_refresh,
|
|
51
|
+
ttl: options.jwks_cache_ttl.to_i,
|
|
52
|
+
min_age: JWKS_REFRESH_MIN_INTERVAL) do
|
|
53
|
+
OmniauthOidc::Logging.instrument("jwks.fetch", jwks_uri: config.jwks_uri) do
|
|
54
|
+
response = OmniauthOidc::HttpClient.get(config.jwks_uri)
|
|
55
|
+
OmniauthOidc::JwkHandler.parse_jwks(response)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
rescue StandardError => e
|
|
59
|
+
OmniauthOidc::Logging.error("Failed to fetch JWKS", error: e.message, jwks_uri: config.jwks_uri)
|
|
60
|
+
raise OmniauthOidc::JwksFetchError, "Failed to fetch JWKS from #{config.jwks_uri}: #{e.message}"
|
|
34
61
|
end
|
|
35
62
|
|
|
36
63
|
def base64_decoded_jwt_secret
|
|
@@ -39,75 +66,168 @@ module OmniAuth
|
|
|
39
66
|
Base64.decode64(options.jwt_secret_base64)
|
|
40
67
|
end
|
|
41
68
|
|
|
69
|
+
# An empty key lets anyone forge HS* tokens (CVE-2026-45363), so never verify with one
|
|
70
|
+
def hmac_secret
|
|
71
|
+
key = secret.to_s
|
|
72
|
+
return key unless key.empty?
|
|
73
|
+
|
|
74
|
+
raise OmniauthOidc::ConfigurationError, "HMAC secret for ID token verification is empty"
|
|
75
|
+
end
|
|
76
|
+
|
|
42
77
|
def verify_id_token!(id_token)
|
|
43
78
|
return unless id_token
|
|
44
79
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
80
|
+
OmniauthOidc::Logging.instrument("id_token.verify", provider: name) do
|
|
81
|
+
decoded = decode_id_token(id_token)
|
|
82
|
+
verify_claims!(decoded)
|
|
83
|
+
decoded
|
|
84
|
+
end
|
|
48
85
|
end
|
|
49
86
|
|
|
50
|
-
def
|
|
51
|
-
|
|
52
|
-
algorithm = decoded.algorithm.to_sym
|
|
87
|
+
def verify_claims!(decoded_token)
|
|
88
|
+
claims = decoded_token.raw_attributes
|
|
53
89
|
|
|
54
|
-
|
|
90
|
+
# Consume the nonce before any check can fail, so it stays single use
|
|
91
|
+
expected_nonce = stored_nonce
|
|
55
92
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
93
|
+
verify_issuer!(claims)
|
|
94
|
+
verify_audience!(claims)
|
|
95
|
+
verify_nonce!(claims, expected_nonce)
|
|
96
|
+
verify_expiration!(claims)
|
|
97
|
+
|
|
98
|
+
decoded_token
|
|
99
|
+
end
|
|
63
100
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
raise if decoded&.header&.key?("kid")
|
|
101
|
+
# The discovery document is validated to always carry an issuer, so this check
|
|
102
|
+
# cannot be skipped by a provider that omits it.
|
|
103
|
+
def verify_issuer!(claims)
|
|
104
|
+
return if claims["iss"] == config.issuer
|
|
69
105
|
|
|
70
|
-
|
|
106
|
+
raise OmniauthOidc::InvalidIssuerError,
|
|
107
|
+
"Issuer mismatch. Expected: #{config.issuer}, Got: #{claims["iss"]}"
|
|
108
|
+
end
|
|
71
109
|
|
|
72
|
-
|
|
110
|
+
def verify_audience!(claims)
|
|
111
|
+
audience = claims["aud"]
|
|
112
|
+
expected_aud = client_options.identifier
|
|
113
|
+
return if audience_matches?(audience, expected_aud)
|
|
73
114
|
|
|
74
|
-
|
|
115
|
+
raise OmniauthOidc::InvalidAudienceError,
|
|
116
|
+
"Audience mismatch. Expected: #{expected_aud}, Got: #{audience}"
|
|
75
117
|
end
|
|
76
118
|
|
|
77
|
-
#
|
|
78
|
-
|
|
79
|
-
|
|
119
|
+
# The expected nonce comes only from the session. Never read it from request params:
|
|
120
|
+
# the caller controls those. Nonce values are left out of messages because they end
|
|
121
|
+
# up in logs.
|
|
122
|
+
def verify_nonce!(claims, expected_nonce)
|
|
123
|
+
if expected_nonce.nil?
|
|
124
|
+
return unless nonce_required?
|
|
80
125
|
|
|
81
|
-
|
|
82
|
-
|
|
126
|
+
raise OmniauthOidc::InvalidNonceError, "No nonce stored in the session for this login"
|
|
127
|
+
end
|
|
128
|
+
return if claims["nonce"] == expected_nonce
|
|
83
129
|
|
|
84
|
-
|
|
85
|
-
configured for #{client_signing_alg}"
|
|
86
|
-
raise CallbackError, error: :invalid_jwt_algorithm, reason: reason, uri: params["error_uri"]
|
|
130
|
+
raise OmniauthOidc::InvalidNonceError, "ID token nonce does not match the authorization request"
|
|
87
131
|
end
|
|
88
132
|
|
|
89
|
-
|
|
90
|
-
|
|
133
|
+
# OIDC Core 3.2.2.1 requires a nonce for the implicit (id_token) flow, so it is
|
|
134
|
+
# always used there, regardless of send_nonce.
|
|
135
|
+
def nonce_required?
|
|
136
|
+
options.send_nonce || options.response_type.to_s == "id_token"
|
|
91
137
|
end
|
|
92
138
|
|
|
93
|
-
|
|
94
|
-
|
|
139
|
+
# exp is required by OIDC Core 3.1.3.7 and must be a NumericDate (RFC 7519 2).
|
|
140
|
+
# Clock skew between us and the provider is tolerated up to clock_skew_leeway.
|
|
141
|
+
def verify_expiration!(claims)
|
|
142
|
+
exp = claims["exp"]
|
|
143
|
+
raise OmniauthOidc::TokenVerificationError, "ID token is missing the exp claim" if exp.nil?
|
|
144
|
+
raise OmniauthOidc::TokenVerificationError, "ID token exp claim is not a number" unless exp.is_a?(Numeric)
|
|
145
|
+
return if Time.now.to_i < exp + clock_skew_leeway
|
|
95
146
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
decoded = decode!(id_token, key)
|
|
99
|
-
rescue JSON::JWS::VerificationFailed, JSON::JWS::UnexpectedAlgorithm, JSON::JWK::UnknownAlgorithm
|
|
100
|
-
next
|
|
101
|
-
end
|
|
147
|
+
raise OmniauthOidc::TokenExpiredError, "Token expired at #{Time.at(exp)}"
|
|
148
|
+
end
|
|
102
149
|
|
|
103
|
-
|
|
104
|
-
|
|
150
|
+
def audience_matches?(audience, expected)
|
|
151
|
+
return audience == expected if audience.is_a?(String)
|
|
152
|
+
return audience.include?(expected) if audience.is_a?(Array)
|
|
105
153
|
|
|
106
|
-
|
|
154
|
+
false
|
|
107
155
|
end
|
|
108
156
|
|
|
109
|
-
def
|
|
110
|
-
|
|
157
|
+
def clock_skew_leeway
|
|
158
|
+
leeway = options.clock_skew_leeway
|
|
159
|
+
return leeway if leeway.is_a?(Integer) && leeway >= 0
|
|
160
|
+
|
|
161
|
+
raise OmniauthOidc::ConfigurationError,
|
|
162
|
+
"clock_skew_leeway must be a non-negative Integer, got #{leeway.inspect}"
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def decode_id_token(id_token)
|
|
166
|
+
# First decode without verification to get the algorithm and kid
|
|
167
|
+
_unverified_payload, unverified_header = JWT.decode(id_token, nil, false)
|
|
168
|
+
algorithm = unverified_header["alg"].to_s
|
|
169
|
+
|
|
170
|
+
validate_algorithm!(algorithm)
|
|
171
|
+
|
|
172
|
+
# Get the appropriate key/secret for verification
|
|
173
|
+
key = keyset_for_algorithm(algorithm, unverified_header["kid"])
|
|
174
|
+
|
|
175
|
+
# Decode and verify
|
|
176
|
+
verify_signature!(id_token, key, algorithm)
|
|
177
|
+
rescue JWT::DecodeError => e
|
|
178
|
+
raise OmniauthOidc::TokenVerificationError, "Invalid JWT format: #{e.message}"
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def keyset_for_algorithm(algorithm, kid = nil)
|
|
182
|
+
return hmac_secret if HMAC_ALGORITHMS.include?(algorithm)
|
|
183
|
+
|
|
184
|
+
keys = public_key
|
|
185
|
+
return keys unless keys.is_a?(Array)
|
|
186
|
+
|
|
187
|
+
# The provider may have rotated its signing keys since the JWKS was cached
|
|
188
|
+
keys = public_key_with_refresh if kid && keys.none? { |key| key.kid == kid }
|
|
189
|
+
OmniauthOidc::JwkHandler.find_key(keys, kid)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def verify_signature!(id_token, key, algorithm)
|
|
193
|
+
payload, _header = JWT.decode(
|
|
194
|
+
id_token,
|
|
195
|
+
key,
|
|
196
|
+
true, # verify signature
|
|
197
|
+
# exp is verified manually in verify_claims!
|
|
198
|
+
{ algorithm: algorithm, verify_expiration: false, nbf_leeway: clock_skew_leeway }
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
# Create our custom IdToken object
|
|
202
|
+
OmniauthOidc::ResponseObjects::IdToken.new(payload.merge("algorithm" => algorithm))
|
|
203
|
+
rescue JWT::VerificationError => e
|
|
204
|
+
raise OmniauthOidc::InvalidSignatureError, "JWT signature verification failed: #{e.message}"
|
|
205
|
+
rescue JWT::IncorrectAlgorithm => e
|
|
206
|
+
raise OmniauthOidc::InvalidAlgorithmError, "Unexpected JWT algorithm: #{e.message}"
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
# The token header is attacker controlled, so the accepted algorithms come from
|
|
210
|
+
# configuration only. "none" is never accepted.
|
|
211
|
+
def validate_algorithm!(algorithm)
|
|
212
|
+
allowed = allowed_signing_algorithms
|
|
213
|
+
return if allowed.include?(algorithm)
|
|
214
|
+
|
|
215
|
+
raise OmniauthOidc::InvalidAlgorithmError,
|
|
216
|
+
"Received JWT is signed with #{algorithm.empty? ? "no algorithm" : algorithm}, " \
|
|
217
|
+
"but only #{allowed.empty? ? "signed tokens" : allowed.join(", ")} are accepted"
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# client_signing_alg when set, otherwise the algorithms the discovery document
|
|
221
|
+
# advertises for ID tokens, otherwise RS256.
|
|
222
|
+
def allowed_signing_algorithms
|
|
223
|
+
algorithms = if options.client_signing_alg
|
|
224
|
+
[options.client_signing_alg]
|
|
225
|
+
else
|
|
226
|
+
Array(config.id_token_signing_alg_values_supported)
|
|
227
|
+
end
|
|
228
|
+
algorithms = [DEFAULT_SIGNING_ALGORITHM] if algorithms.empty?
|
|
229
|
+
|
|
230
|
+
algorithms.map(&:to_s) - ["none"]
|
|
111
231
|
end
|
|
112
232
|
|
|
113
233
|
def configured_public_key
|
|
@@ -120,31 +240,15 @@ module OmniAuth
|
|
|
120
240
|
|
|
121
241
|
def parse_x509_key(key)
|
|
122
242
|
OpenSSL::X509::Certificate.new(key).public_key
|
|
243
|
+
rescue OpenSSL::X509::CertificateError => e
|
|
244
|
+
raise OmniauthOidc::TokenVerificationError, "Invalid X.509 certificate: #{e.message}"
|
|
123
245
|
end
|
|
124
246
|
|
|
125
247
|
def parse_jwk_key(key)
|
|
126
248
|
json = key.is_a?(String) ? JSON.parse(key) : key
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def decode(str)
|
|
133
|
-
UrlSafeBase64.decode64(str).unpack1("B*").to_i(2).to_s
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
def user_info
|
|
137
|
-
return @user_info if @user_info
|
|
138
|
-
|
|
139
|
-
if access_token.id_token
|
|
140
|
-
decoded = decode_id_token(access_token.id_token).raw_attributes
|
|
141
|
-
|
|
142
|
-
@user_info = ::OpenIDConnect::ResponseObject::UserInfo.new(
|
|
143
|
-
access_token.userinfo!.raw_attributes.merge(decoded)
|
|
144
|
-
)
|
|
145
|
-
else
|
|
146
|
-
@user_info = access_token.userinfo!
|
|
147
|
-
end
|
|
249
|
+
OmniauthOidc::JwkHandler.parse_jwks(json)
|
|
250
|
+
rescue JSON::ParserError => e
|
|
251
|
+
raise OmniauthOidc::TokenVerificationError, "Invalid JWK format: #{e.message}"
|
|
148
252
|
end
|
|
149
253
|
end
|
|
150
254
|
end
|
|
@@ -5,16 +5,19 @@ require "timeout"
|
|
|
5
5
|
require "net/http"
|
|
6
6
|
require "open-uri"
|
|
7
7
|
require "omniauth"
|
|
8
|
-
require "openid_connect"
|
|
9
|
-
require "openid_config_parser"
|
|
10
8
|
require "forwardable"
|
|
11
|
-
require "
|
|
9
|
+
require "jwt"
|
|
10
|
+
require "ostruct"
|
|
11
|
+
require "openssl"
|
|
12
12
|
|
|
13
|
-
Dir
|
|
13
|
+
# Explicit requires instead of Dir glob for clarity and load order control
|
|
14
|
+
require_relative "oidc/request"
|
|
15
|
+
require_relative "oidc/callback"
|
|
16
|
+
require_relative "oidc/verify"
|
|
14
17
|
|
|
15
18
|
module OmniAuth
|
|
16
19
|
module Strategies
|
|
17
|
-
# OIDC strategy for
|
|
20
|
+
# OIDC strategy for OmniAuth
|
|
18
21
|
class Oidc
|
|
19
22
|
include OmniAuth::Strategy
|
|
20
23
|
include Request
|
|
@@ -28,6 +31,8 @@ module OmniAuth
|
|
|
28
31
|
"code" => { exception_class: OmniauthOidc::MissingCodeError, key: :missing_code }.freeze
|
|
29
32
|
}.freeze
|
|
30
33
|
|
|
34
|
+
REQUIRED_OPTIONS = %i[identifier secret config_endpoint].freeze
|
|
35
|
+
|
|
31
36
|
def_delegator :request, :params
|
|
32
37
|
|
|
33
38
|
option :name, :oidc # to separate each oidc provider available in the app
|
|
@@ -67,8 +72,8 @@ module OmniAuth
|
|
|
67
72
|
option :post_logout_redirect_uri
|
|
68
73
|
option :extra_authorize_params, {}
|
|
69
74
|
option :allow_authorize_params, []
|
|
70
|
-
option :uid_field, "sub"
|
|
71
|
-
option :pkce,
|
|
75
|
+
option :uid_field, "sub" # Deprecated: never had an effect, the uid is always `sub`. Removed in 2.0.0
|
|
76
|
+
option :pkce, true
|
|
72
77
|
option :pkce_verifier, nil
|
|
73
78
|
option :pkce_options, {
|
|
74
79
|
code_challenge: proc { |verifier|
|
|
@@ -79,8 +84,21 @@ module OmniAuth
|
|
|
79
84
|
|
|
80
85
|
option :logout_path, "/logout"
|
|
81
86
|
|
|
87
|
+
# JWKS and discovery document cache TTLs in seconds
|
|
88
|
+
option :jwks_cache_ttl, OmniauthOidc::JwksCache::DEFAULT_TTL
|
|
89
|
+
option :discovery_cache_ttl, OmniauthOidc::ConfigFetcher::DEFAULT_CACHE_TTL
|
|
90
|
+
|
|
91
|
+
# Seconds of clock drift tolerated when checking ID token exp and nbf
|
|
92
|
+
option :clock_skew_leeway, 60
|
|
93
|
+
|
|
94
|
+
def initialize(app, *args, &block)
|
|
95
|
+
super
|
|
96
|
+
warn_uid_field_deprecation
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Always the subject claim: the only identifier OIDC guarantees to be stable and unique per issuer
|
|
82
100
|
def uid
|
|
83
|
-
user_info.
|
|
101
|
+
user_info.sub
|
|
84
102
|
end
|
|
85
103
|
|
|
86
104
|
info do
|
|
@@ -104,27 +122,47 @@ module OmniAuth
|
|
|
104
122
|
|
|
105
123
|
credentials do
|
|
106
124
|
{
|
|
107
|
-
id_token: access_token
|
|
108
|
-
token: access_token
|
|
109
|
-
refresh_token: access_token
|
|
110
|
-
expires_in: access_token
|
|
111
|
-
scope: access_token
|
|
125
|
+
id_token: access_token&.id_token,
|
|
126
|
+
token: access_token&.access_token,
|
|
127
|
+
refresh_token: access_token&.refresh_token,
|
|
128
|
+
expires_in: access_token&.expires_in,
|
|
129
|
+
scope: access_token&.scope
|
|
112
130
|
}
|
|
113
131
|
end
|
|
114
132
|
|
|
115
|
-
# Initialize
|
|
133
|
+
# Initialize our custom OIDC Client with options
|
|
116
134
|
def client
|
|
117
|
-
@client ||=
|
|
135
|
+
@client ||= begin
|
|
136
|
+
set_client_endpoints
|
|
137
|
+
OmniauthOidc::Client.new(
|
|
138
|
+
identifier: client_options.identifier,
|
|
139
|
+
secret: client_options.secret,
|
|
140
|
+
authorization_endpoint: client_options.authorization_endpoint,
|
|
141
|
+
token_endpoint: client_options.token_endpoint,
|
|
142
|
+
userinfo_endpoint: client_options.userinfo_endpoint,
|
|
143
|
+
redirect_uri: redirect_uri
|
|
144
|
+
)
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def set_client_endpoints
|
|
149
|
+
client_options.authorization_endpoint ||= config.authorization_endpoint
|
|
150
|
+
client_options.token_endpoint ||= config.token_endpoint
|
|
151
|
+
client_options.userinfo_endpoint ||= config.userinfo_endpoint
|
|
152
|
+
client_options.jwks_uri ||= config.jwks_uri
|
|
153
|
+
client_options.end_session_endpoint ||= config.end_session_endpoint
|
|
118
154
|
end
|
|
119
155
|
|
|
120
|
-
# Config is
|
|
156
|
+
# Config is built from the json response from the OIDC config endpoint.
|
|
157
|
+
# OmniAuth dups the strategy per request, so the process-wide cache is what avoids
|
|
158
|
+
# refetching the discovery document on every request.
|
|
121
159
|
def config
|
|
122
|
-
|
|
123
|
-
raise Error,
|
|
124
|
-
"Configuration endpoint is missing from options"
|
|
125
|
-
end
|
|
160
|
+
validate_configuration!
|
|
126
161
|
|
|
127
|
-
|
|
162
|
+
endpoint = client_options.config_endpoint
|
|
163
|
+
@config ||= OmniauthOidc::Logging.instrument("config.fetch", config_endpoint: endpoint) do
|
|
164
|
+
OmniauthOidc::ConfigFetcher.fetch_cached(endpoint, ttl: options.discovery_cache_ttl.to_i)
|
|
165
|
+
end
|
|
128
166
|
end
|
|
129
167
|
|
|
130
168
|
# Detects if current request is for the logout url and makes a redirect to end session with OIDC provider
|
|
@@ -148,6 +186,25 @@ module OmniAuth
|
|
|
148
186
|
|
|
149
187
|
private
|
|
150
188
|
|
|
189
|
+
def warn_uid_field_deprecation
|
|
190
|
+
return if options.uid_field.to_s == "sub"
|
|
191
|
+
|
|
192
|
+
OmniauthOidc::Logging.warn("The uid_field option is deprecated and has no effect: the uid is always the " \
|
|
193
|
+
"sub claim. Remove it from the #{name} provider; it is removed in 2.0.0.")
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def validate_configuration!
|
|
197
|
+
missing = []
|
|
198
|
+
missing << :identifier if client_options.identifier.to_s.empty?
|
|
199
|
+
missing << :secret if client_options.secret.to_s.empty?
|
|
200
|
+
missing << :config_endpoint if client_options.config_endpoint.to_s.empty?
|
|
201
|
+
|
|
202
|
+
return if missing.empty?
|
|
203
|
+
|
|
204
|
+
raise OmniauthOidc::MissingConfigurationError,
|
|
205
|
+
"Missing required configuration: #{missing.join(", ")}"
|
|
206
|
+
end
|
|
207
|
+
|
|
151
208
|
def issuer
|
|
152
209
|
@issuer ||= config.issuer
|
|
153
210
|
end
|
|
@@ -158,7 +215,8 @@ module OmniAuth
|
|
|
158
215
|
|
|
159
216
|
# By default Returns all scopes supported by the OIDC provider
|
|
160
217
|
def scope
|
|
161
|
-
options.scope || config.scopes_supported || [:
|
|
218
|
+
value = options.scope || config.scopes_supported || [:openid]
|
|
219
|
+
value.is_a?(Array) ? value.join(" ") : value
|
|
162
220
|
end
|
|
163
221
|
|
|
164
222
|
def authorization_code
|
|
@@ -169,12 +227,21 @@ module OmniAuth
|
|
|
169
227
|
options.client_options
|
|
170
228
|
end
|
|
171
229
|
|
|
230
|
+
# Session key helpers with provider namespacing
|
|
231
|
+
def session_key(suffix)
|
|
232
|
+
"omniauth.#{name}.#{suffix}"
|
|
233
|
+
end
|
|
234
|
+
|
|
172
235
|
def stored_state
|
|
173
|
-
session.delete("
|
|
236
|
+
session.delete(session_key("state"))
|
|
174
237
|
end
|
|
175
238
|
|
|
176
239
|
def new_nonce
|
|
177
|
-
session["
|
|
240
|
+
session[session_key("nonce")] = SecureRandom.hex(16)
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def stored_nonce
|
|
244
|
+
session.delete(session_key("nonce"))
|
|
178
245
|
end
|
|
179
246
|
|
|
180
247
|
def script_name
|
|
@@ -210,14 +277,6 @@ module OmniAuth
|
|
|
210
277
|
@logout_path_pattern ||= /\A#{Regexp.quote(request.base_url)}#{options.logout_path}/
|
|
211
278
|
end
|
|
212
279
|
|
|
213
|
-
# Strips port and host from strings with OIDC endpoints
|
|
214
|
-
def resolve_endpoint_from_host(host, endpoint)
|
|
215
|
-
start_index = endpoint.index(host) + host.length
|
|
216
|
-
endpoint = endpoint[start_index..]
|
|
217
|
-
endpoint = "/#{endpoint}" unless endpoint.start_with?("/")
|
|
218
|
-
endpoint
|
|
219
|
-
end
|
|
220
|
-
|
|
221
280
|
# Override for the CallbackError class
|
|
222
281
|
class CallbackError < StandardError
|
|
223
282
|
attr_accessor :error, :error_reason, :error_uri
|
|
@@ -225,8 +284,8 @@ module OmniAuth
|
|
|
225
284
|
def initialize(data)
|
|
226
285
|
super
|
|
227
286
|
self.error = data[:error]
|
|
228
|
-
self.error_reason = data[:reason]
|
|
229
|
-
self.error_uri = data[:uri]
|
|
287
|
+
self.error_reason = data[:error_reason] || data[:reason]
|
|
288
|
+
self.error_uri = data[:error_uri] || data[:uri]
|
|
230
289
|
end
|
|
231
290
|
|
|
232
291
|
def message
|
data/lib/omniauth_oidc.rb
CHANGED
|
@@ -2,4 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "omniauth/oidc/version"
|
|
4
4
|
require_relative "omniauth/oidc/errors"
|
|
5
|
+
require_relative "omniauth/oidc/logging"
|
|
6
|
+
require_relative "omniauth/oidc/ttl_cache"
|
|
7
|
+
require_relative "omniauth/oidc/jwks_cache"
|
|
8
|
+
require_relative "omniauth/oidc/http_client"
|
|
9
|
+
require_relative "omniauth/oidc/response_objects"
|
|
10
|
+
require_relative "omniauth/oidc/client"
|
|
11
|
+
require_relative "omniauth/oidc/config_fetcher"
|
|
12
|
+
require_relative "omniauth/oidc/jwk_handler"
|
|
5
13
|
require_relative "omniauth/strategies/oidc"
|
data/omniauth_oidc.gemspec
CHANGED
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
19
19
|
spec.metadata["source_code_uri"] = "https://github.com/msuliq/omniauth_oidc"
|
|
20
20
|
spec.metadata["changelog_uri"] = "https://github.com/msuliq/omniauth_oidc/blob/main/CHANGELOG.md"
|
|
21
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
21
22
|
|
|
22
23
|
# Specify which files should be added to the gem when it is released.
|
|
23
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
@@ -31,11 +32,13 @@ Gem::Specification.new do |spec|
|
|
|
31
32
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
32
33
|
spec.require_paths = ["lib"]
|
|
33
34
|
|
|
34
|
-
#
|
|
35
|
-
|
|
36
|
-
spec.add_dependency "
|
|
37
|
-
spec.add_dependency "
|
|
38
|
-
|
|
35
|
+
# Runtime dependencies
|
|
36
|
+
# Excludes releases affected by CVE-2026-45363 (empty-key HMAC bypass): fixed in 2.10.3 and 3.2.0
|
|
37
|
+
spec.add_dependency "jwt", ">= 2.10.3", "!= 3.0.0", "!= 3.1.0", "!= 3.1.1", "!= 3.1.2", "< 4.0"
|
|
38
|
+
spec.add_dependency "omniauth", "~> 2.1"
|
|
39
|
+
|
|
40
|
+
# Ruby 4.0+ compatibility - ostruct no longer in default gems
|
|
41
|
+
# Users on Ruby 4.0+ should add 'gem "ostruct"' to their Gemfile
|
|
39
42
|
|
|
40
43
|
# For more information and examples about making a new gem, check out our
|
|
41
44
|
# guide at: https://bundler.io/guides/creating_gem.html
|