Skip to content

Commit

Permalink
Log missing kid when ID token verification fails
Browse files Browse the repository at this point in the history
This will help debug issues when the JWT is signed with an
unknown `kid`.
  • Loading branch information
stanhu committed Sep 10, 2024
1 parent 9b2a67d commit ab69caa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/omniauth/strategies/openid_connect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ def decode_id_token(id_token)
# done. However, if there is no kid, then we try each key
# individually to see if one works:
# https://github.com/nov/json-jwt/pull/92#issuecomment-824654949
raise if decoded&.header&.key?('kid')
if decoded&.header&.key?('kid')
kid = decoded.header['kid']
raise JSON::JWK::Set::KidNotFound.new("kid '#{kid}' not found")
end

decoded = decode_with_each_key!(id_token, keyset)

Expand Down
4 changes: 3 additions & 1 deletion test/lib/omniauth/strategies/openid_connect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,11 @@ def test_callback_phase_with_id_token_with_kid_and_no_matching_kid
strategy.unstub(:user_info)
strategy.call!('rack.session' => { 'omniauth.state' => state, 'omniauth.nonce' => nonce })

assert_raises JSON::JWK::Set::KidNotFound do
error = assert_raises JSON::JWK::Set::KidNotFound do
strategy.callback_phase
end

assert_match /kid '.*' not found/, error.message
end

def test_callback_phase_with_id_token_with_hs256
Expand Down

0 comments on commit ab69caa

Please sign in to comment.