forked from RIPAGlobal/omniauth-entra-id
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve ID token validation and data extraction
* Removes use of the 'upn' claim for email addresses, since if an 'email' claim is not provided, the user's email is not verified * Uses the combination of 'tid' and 'oid' as a uuid, since 'oid' is only unique within a single-tenant * Adds validation of 'aud', 'iss', 'nbf' and 'exp' id token claims Ref RIPAGlobal#33
- Loading branch information
1 parent
b239e6d
commit 295de28
Showing
2 changed files
with
147 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,10 +380,22 @@ def adfs? | |
end | ||
|
||
let(:id_token_info) do | ||
issued_at = Time.now.utc.to_i | ||
expires_at = (Time.now + 3600).to_i | ||
{ | ||
oid: 'my_id', | ||
name: 'Bob Doe', | ||
email: '[email protected]', | ||
ver: '2.0', | ||
iss: 'https://login.microsoftonline.com/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0', | ||
sub: 'sdfkjllAkdkWkeiidkcXKfjjsl', | ||
aud: 'id', | ||
exp: expires_at, | ||
iat: issued_at, | ||
nbf: issued_at, | ||
name: 'Bob Doe', | ||
preferred_username: '[email protected]', | ||
oid: 'my_id', | ||
email: '[email protected]', | ||
tid: '9188040d-6c67-4c5b-b112-36a304b66dad', | ||
aio: 'KSslldiwDkfjjsoeiruosKD', | ||
unique_name: 'bobby' | ||
} | ||
end | ||
|
@@ -413,15 +425,27 @@ def adfs? | |
end | ||
|
||
it 'returns correct uid' do | ||
expect(subject.uid).to eq('my_id') | ||
expect(subject.uid).to eq('9188040d-6c67-4c5b-b112-36a304b66dadmy_id') | ||
end | ||
end # "context 'with information only in the ID token' do" | ||
|
||
context 'with extra information in the auth token' do | ||
let(:auth_token_info) do | ||
issued_at = Time.now.utc.to_i | ||
expires_at = (Time.now + 3600).to_i | ||
{ | ||
oid: 'overridden_id', | ||
email: '[email protected]', | ||
ver: '2.0', | ||
iss: 'https://login.microsoftonline.com/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0', | ||
sub: 'sdfkjllAkdkWkeiidkcXKfjjsl', | ||
aud: 'id', | ||
exp: expires_at, | ||
iat: issued_at, | ||
nbf: issued_at, | ||
preferred_username: '[email protected]', | ||
oid: 'overridden_id', | ||
email: '[email protected]', | ||
tid: '9188040d-6c67-4c5b-b112-36a304b66dad', | ||
aio: 'KSslldiwDkfjjsoeiruosKD', | ||
unique_name: 'Bobby Definitely Doe', | ||
given_name: 'Bob', | ||
family_name: 'Doe' | ||
|
@@ -447,9 +471,100 @@ def adfs? | |
end | ||
|
||
it 'returns correct uid' do | ||
expect(subject.uid).to eq('overridden_id') | ||
expect(subject.uid).to eq('9188040d-6c67-4c5b-b112-36a304b66dadoverridden_id') | ||
end | ||
end # "context 'with extra information in the auth token' do" | ||
|
||
context 'with an invalid audience' do | ||
let(:id_token_info) do | ||
issued_at = Time.now.utc.to_i | ||
expires_at = (Time.now + 3600).to_i | ||
{ | ||
ver: '2.0', | ||
iss: 'https://login.microsoftonline.com/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0', | ||
sub: 'sdfkjllAkdkWkeiidkcXKfjjsl', | ||
aud: 'other-id', | ||
exp: expires_at, | ||
iat: issued_at, | ||
nbf: issued_at, | ||
name: 'Bob Doe', | ||
preferred_username: '[email protected]', | ||
oid: 'my_id', | ||
email: '[email protected]', | ||
tid: '9188040d-6c67-4c5b-b112-36a304b66dad', | ||
aio: 'KSslldiwDkfjjsoeiruosKD', | ||
unique_name: 'bobby' | ||
} | ||
end | ||
|
||
it 'fails validation' do | ||
expect { subject.info }.to raise_error(JWT::InvalidAudError) | ||
end | ||
end | ||
|
||
context 'with an invalid issuer' do | ||
subject do | ||
OmniAuth::Strategies::AzureActivedirectoryV2.new(app, {client_id: 'id', client_secret: 'secret', tenant_id: 'test-tenant'}) | ||
end | ||
|
||
it 'fails validation' do | ||
expect { subject.info }.to raise_error(JWT::InvalidIssuerError) | ||
end | ||
end | ||
|
||
context 'with an invalid not_before' do | ||
let(:id_token_info) do | ||
issued_at = (Time.now + 70).to_i # Since leeway is 60 seconds | ||
expires_at = (Time.now + 3600).to_i | ||
{ | ||
ver: '2.0', | ||
iss: 'https://login.microsoftonline.com/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0', | ||
sub: 'sdfkjllAkdkWkeiidkcXKfjjsl', | ||
aud: 'id', | ||
exp: expires_at, | ||
iat: issued_at, | ||
nbf: issued_at, | ||
name: 'Bob Doe', | ||
preferred_username: '[email protected]', | ||
oid: 'my_id', | ||
email: '[email protected]', | ||
tid: '9188040d-6c67-4c5b-b112-36a304b66dad', | ||
aio: 'KSslldiwDkfjjsoeiruosKD', | ||
unique_name: 'bobby' | ||
} | ||
end | ||
|
||
it 'fails validation' do | ||
expect { subject.info }.to raise_error(JWT::ImmatureSignature) | ||
end | ||
end | ||
|
||
context 'with an expired token' do | ||
let(:id_token_info) do | ||
issued_at = (Time.now - 3600).to_i | ||
expires_at = (Time.now - 70).to_i # Since leeway is 60 seconds | ||
{ | ||
ver: '2.0', | ||
iss: 'https://login.microsoftonline.com/9188040d-6c67-4c5b-b112-36a304b66dad/v2.0', | ||
sub: 'sdfkjllAkdkWkeiidkcXKfjjsl', | ||
aud: 'id', | ||
exp: expires_at, | ||
iat: issued_at, | ||
nbf: issued_at, | ||
name: 'Bob Doe', | ||
preferred_username: '[email protected]', | ||
oid: 'my_id', | ||
email: '[email protected]', | ||
tid: '9188040d-6c67-4c5b-b112-36a304b66dad', | ||
aio: 'KSslldiwDkfjjsoeiruosKD', | ||
unique_name: 'bobby' | ||
} | ||
end | ||
|
||
it 'fails validation' do | ||
expect { subject.info }.to raise_error(JWT::ExpiredSignature) | ||
end | ||
end | ||
end # "describe 'raw_info' do" | ||
|
||
describe 'callback_url' do | ||
|