Skip to content

Commit

Permalink
Only pass along audience if it is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelvanrijn committed Jul 3, 2024
1 parent 43407b6 commit 94c649a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 8 additions & 4 deletions lib/omniauth/strategies/openid_connect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,14 @@ def configured_response_type
def verify_id_token!(id_token)
return unless id_token

decode_id_token(id_token).verify!(issuer: options.issuer,
client_id: client_options.identifier,
audience: client_options.audience,
nonce: params['nonce'].presence || stored_nonce)
verify_kwargs = {
issuer: options.issuer,
client_id: client_options.identifier,
nonce: params['nonce'].presence || stored_nonce,
}
verify_kwargs.merge!(audience: client_options.audience) if client_options.audience

decode_id_token(id_token).verify!(**verify_kwargs)
end

class CallbackError < StandardError
Expand Down
5 changes: 3 additions & 2 deletions test/lib/omniauth/strategies/openid_connect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,11 @@ def test_callback_phase_with_audience
state = SecureRandom.hex(16)
strategy.options.response_type = 'id_token'
strategy.options.issuer = 'example.com'
strategy.options.client_options.audience = "my_audience"
strategy.options.client_options.audience = 'my_audience'

id_token = stub('OpenIDConnect::ResponseObject::IdToken')
id_token.expects(:verify!).with(issuer: strategy.options.issuer, client_id: @identifier, audience: "my_audience", nonce: nonce).returns(true)
id_token.expects(:verify!).with(issuer: strategy.options.issuer, client_id: @identifier, audience: 'my_audience',
nonce: nonce).returns(true)
id_token.stubs(:raw_attributes, :to_h).returns(payload)

request.stubs(:params).returns('state' => state, 'nounce' => nonce, 'id_token' => id_token)
Expand Down

0 comments on commit 94c649a

Please sign in to comment.