Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/omniauth/strategies/openid_connect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ class OpenIDConnect
end

extra do
{raw_info: user_info.raw_attributes}
{
raw_info: user_info.raw_attributes,
id_token: id_token.raw_attributes
}
end

credentials do
Expand Down Expand Up @@ -174,6 +177,9 @@ def decode_id_token(id_token)
::OpenIDConnect::ResponseObject::IdToken.decode(id_token, public_key)
end

def id_token
decode_id_token(access_token.id_token)
end

def client_options
options.client_options
Expand Down
22 changes: 21 additions & 1 deletion test/lib/omniauth/strategies/openid_connect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def test_callback_phase(session = {}, params = {})

id_token = stub('OpenIDConnect::ResponseObject::IdToken')
id_token.stubs(:verify!).with({:issuer => strategy.options.issuer, :client_id => @identifier, :nonce => nonce}).returns(true)
id_token.stubs(:raw_attributes)
::OpenIDConnect::ResponseObject::IdToken.stubs(:decode).returns(id_token)

strategy.unstub(:user_info)
Expand Down Expand Up @@ -102,6 +103,7 @@ def test_callback_phase_with_discovery

id_token = stub('OpenIDConnect::ResponseObject::IdToken')
id_token.stubs(:verify!).with({:issuer => 'https://example.com/', :client_id => @identifier, :nonce => nonce}).returns(true)
id_token.stubs(:raw_attributes)
::OpenIDConnect::ResponseObject::IdToken.stubs(:decode).returns(id_token)

strategy.unstub(:user_info)
Expand Down Expand Up @@ -202,7 +204,23 @@ def test_info
end

def test_extra
assert_equal({ raw_info: user_info.as_json }, strategy.extra)
id_token = stub('OpenIDConnect::ResponseObject::IdToken')
id_token.stubs(:verify!).returns(true)
id_token.stubs(:raw_attributes).returns(iss: 'https://example.com', sub: 'sub123')
::OpenIDConnect::ResponseObject::IdToken.stubs(:decode).returns(id_token)

access_token = stub('OpenIDConnect::AccessToken')
access_token.stubs(:id_token)
client.expects(:access_token!).returns(access_token)

extra = {
raw_info: user_info.as_json,
id_token: {
iss: 'https://example.com',
sub: 'sub123'
}
}
assert_equal(extra, strategy.extra)
end

def test_credentials
Expand All @@ -212,6 +230,7 @@ def test_credentials

id_token = stub('OpenIDConnect::ResponseObject::IdToken')
id_token.stubs(:verify!).returns(true)
id_token.stubs(:raw_attributes)
::OpenIDConnect::ResponseObject::IdToken.stubs(:decode).returns(id_token)

access_token = stub('OpenIDConnect::AccessToken')
Expand Down Expand Up @@ -302,6 +321,7 @@ def test_option_client_auth_method

id_token = stub('OpenIDConnect::ResponseObject::IdToken')
id_token.stubs(:verify!).with({:issuer => strategy.options.issuer, :client_id => @identifier, :nonce => nonce}).returns(true)
id_token.stubs(:raw_attributes)
::OpenIDConnect::ResponseObject::IdToken.stubs(:decode).returns(id_token)

HTTPClient.any_instance.stubs(:post).with(
Expand Down