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
6 changes: 5 additions & 1 deletion lib/omniauth/microsoft_graph/domain_verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def verify!
# This means while it's not suitable for consistently identifying a user
# (the domain might change), it is suitable for verifying membership in
# a given domain.
return true if email_domain.casecmp?(upn_domain) ||
return true if email_domain&.casecmp?(upn_domain) ||
skip_verification == true ||
(skip_verification.is_a?(Array) && skip_verification.include?(email_domain)) ||
domain_verified_jwt_claim
Expand All @@ -61,6 +61,10 @@ def verify!
# To get to it, we need to decode the ID token with the key material from Microsoft's
# OIDC configuration endpoint, and inspect it for the claim in question.
def domain_verified_jwt_claim
# The ID token is missing if the token request did not include the
# `openid` scope or the tenant does not issue one.
return false unless id_token

oidc_config = access_token.get(OIDC_CONFIG_URL).parsed
algorithms = oidc_config['id_token_signing_alg_values_supported']
jwks = get_jwks(oidc_config)
Expand Down
17 changes: 17 additions & 0 deletions spec/omniauth/microsoft_graph/domain_verifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
let(:options) { super().merge(skip_domain_verification: true) }

it { is_expected.to be_truthy }

context 'and the auth hash has no email' do
let(:email) { nil }

it { is_expected.to be_truthy }
end
end

context 'when the email domain is explicitly permitted' do
Expand Down Expand Up @@ -109,7 +115,18 @@
end
end

context 'when there is no email and no ID token' do
let(:email) { nil }

it 'raises a DomainVerificationError without fetching the OIDC configuration' do
expect(access_token).not_to receive(:get)
expect { result }.to raise_error OmniAuth::MicrosoftGraph::DomainVerificationError
end
end

context 'when all verification strategies fail' do
let(:id_token) { 'not-a-jwt' }

before { allow(access_token).to receive(:get).and_raise(::OAuth2::Error.new('whoops')) }

it 'raises a DomainVerificationError' do
Expand Down
Loading