Skip to content

Commit 94c649a

Browse files
committed
Only pass along audience if it is specified
1 parent 43407b6 commit 94c649a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/omniauth/strategies/openid_connect.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,14 @@ def configured_response_type
465465
def verify_id_token!(id_token)
466466
return unless id_token
467467

468-
decode_id_token(id_token).verify!(issuer: options.issuer,
469-
client_id: client_options.identifier,
470-
audience: client_options.audience,
471-
nonce: params['nonce'].presence || stored_nonce)
468+
verify_kwargs = {
469+
issuer: options.issuer,
470+
client_id: client_options.identifier,
471+
nonce: params['nonce'].presence || stored_nonce,
472+
}
473+
verify_kwargs.merge!(audience: client_options.audience) if client_options.audience
474+
475+
decode_id_token(id_token).verify!(**verify_kwargs)
472476
end
473477

474478
class CallbackError < StandardError

test/lib/omniauth/strategies/openid_connect_test.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,11 @@ def test_callback_phase_with_audience
252252
state = SecureRandom.hex(16)
253253
strategy.options.response_type = 'id_token'
254254
strategy.options.issuer = 'example.com'
255-
strategy.options.client_options.audience = "my_audience"
255+
strategy.options.client_options.audience = 'my_audience'
256256

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

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

0 commit comments

Comments
 (0)