-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Authn OIDC V2: Enable refresh token response for auth code exchange
- Loading branch information
1 parent
b35fc96
commit e8ab69d
Showing
10 changed files
with
329 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,17 +3,23 @@ | |
require 'spec_helper' | ||
|
||
RSpec.describe(Authentication::AuthnOidc::V2::Client) do | ||
let(:authn_config) do | ||
{ | ||
:provider_uri => 'https://dev-92899796.okta.com/oauth2/default', | ||
:redirect_uri => 'http://localhost:3000/authn-oidc/okta-2/cucumber/authenticate', | ||
:client_id => '0oa3w3xig6rHiu9yT5d7', | ||
:client_secret => 'e349BMTTIpLO-rPuPqLLkLyH_pO-loUzhIVJCrHj', | ||
:claim_mapping => 'foo', | ||
:nonce => '1656b4264b60af659fce', | ||
:state => 'state', | ||
:account => 'bar', | ||
:service_id => 'baz' | ||
} | ||
end | ||
|
||
let(:authenticator) do | ||
Authentication::AuthnOidc::V2::DataObjects::Authenticator.new( | ||
provider_uri: 'https://dev-92899796.okta.com/oauth2/default', | ||
redirect_uri: 'http://localhost:3000/authn-oidc/okta-2/cucumber/authenticate', | ||
client_id: '0oa3w3xig6rHiu9yT5d7', | ||
client_secret: 'e349BMTTIpLO-rPuPqLLkLyH_pO-loUzhIVJCrHj', | ||
claim_mapping: 'foo', | ||
nonce: '1656b4264b60af659fce', | ||
state: 'state', | ||
account: 'bar', | ||
service_id: 'baz' | ||
**authn_config | ||
) | ||
end | ||
|
||
|
@@ -29,13 +35,16 @@ | |
# Because JWT tokens have an expiration timeframe, we need to hold | ||
# time constant after caching the request. | ||
travel_to(Time.parse("2022-06-30 16:42:17 +0000")) do | ||
token = client.callback( | ||
id_token, refresh_token = client.callback( | ||
code: 'qdDm7On1dEEzNmMlk2bF7IcOF8gCgfvgMCMXXXDlYEE' | ||
) | ||
expect(token).to be_a_kind_of(OpenIDConnect::ResponseObject::IdToken) | ||
expect(token.raw_attributes['nonce']).to eq('1656b4264b60af659fce') | ||
expect(token.raw_attributes['preferred_username']).to eq('[email protected]') | ||
expect(token.aud).to eq('0oa3w3xig6rHiu9yT5d7') | ||
|
||
expect(id_token).to be_a_kind_of(OpenIDConnect::ResponseObject::IdToken) | ||
expect(id_token.raw_attributes['nonce']).to eq('1656b4264b60af659fce') | ||
expect(id_token.raw_attributes['preferred_username']).to eq('[email protected]') | ||
expect(id_token.aud).to eq('0oa3w3xig6rHiu9yT5d7') | ||
|
||
expect(refresh_token).to be_nil | ||
end | ||
end | ||
end | ||
|
@@ -97,6 +106,36 @@ | |
end | ||
end | ||
end | ||
|
||
context 'when refresh token flow is enabled' do | ||
# The 'offline_access' scope enables Okta's refresh token flow | ||
let(:authenticator) do | ||
Authentication::AuthnOidc::V2::DataObjects::Authenticator.new( | ||
**authn_config.merge!({ :provider_scope => 'offline_access' }) | ||
) | ||
end | ||
|
||
context 'when credentials are valid' do | ||
it 'returns valid ID and refresh tokens', vcr: 'authenticators/authn-oidc/v2/client_callback-valid_oidc_credentials_and_refresh' do | ||
# Because JWT tokens have an expiration timeframe, we need to hold | ||
# time constant after caching the request. | ||
travel_to(Time.parse("2022-06-30 16:42:17 +0000")) do | ||
id_token, refresh_token = client.callback( | ||
code: 'qdDm7On1dEEzNmMlk2bF7IcOF8gCgfvgMCMXXXDlYEE' | ||
) | ||
|
||
expect(id_token).to be_a_kind_of(OpenIDConnect::ResponseObject::IdToken) | ||
expect(id_token.raw_attributes['nonce']).to eq('1656b4264b60af659fce') | ||
expect(id_token.raw_attributes['preferred_username']).to eq('[email protected]') | ||
expect(id_token.aud).to eq('0oa3w3xig6rHiu9yT5d7') | ||
|
||
expect(refresh_token).not_to be_nil | ||
expect(refresh_token).to be_a_kind_of(String) | ||
expect(refresh_token).to eq('kXMJFtgtaEpOGn0Zk2x15i8umXIWp4aqY1Mh7zscfGI') | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe '.oidc_client' do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.