Skip to content

Commit ab69caa

Browse files
committed
Log missing kid when ID token verification fails
This will help debug issues when the JWT is signed with an unknown `kid`.
1 parent 9b2a67d commit ab69caa

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/omniauth/strategies/openid_connect.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ def decode_id_token(id_token)
317317
# done. However, if there is no kid, then we try each key
318318
# individually to see if one works:
319319
# https://github.com/nov/json-jwt/pull/92#issuecomment-824654949
320-
raise if decoded&.header&.key?('kid')
320+
if decoded&.header&.key?('kid')
321+
kid = decoded.header['kid']
322+
raise JSON::JWK::Set::KidNotFound.new("kid '#{kid}' not found")
323+
end
321324

322325
decoded = decode_with_each_key!(id_token, keyset)
323326

test/lib/omniauth/strategies/openid_connect_test.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,11 @@ def test_callback_phase_with_id_token_with_kid_and_no_matching_kid
338338
strategy.unstub(:user_info)
339339
strategy.call!('rack.session' => { 'omniauth.state' => state, 'omniauth.nonce' => nonce })
340340

341-
assert_raises JSON::JWK::Set::KidNotFound do
341+
error = assert_raises JSON::JWK::Set::KidNotFound do
342342
strategy.callback_phase
343343
end
344+
345+
assert_match /kid '.*' not found/, error.message
344346
end
345347

346348
def test_callback_phase_with_id_token_with_hs256

0 commit comments

Comments
 (0)