Skip to content

Commit ae994f2

Browse files
Add optional skip_issuer parameter to IdToken.verify!
This is especially useful when using Microsoft Entra ID common endpoint, as the issuer could be from another tenant. When using this parameter it is recommended to set the audience as this stays the same even if the issuer is from another tenant. Related omniauth/omniauth_openid_connect#166 Closes nov#95
1 parent e1eb8ea commit ae994f2

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/openid_connect/response_object/id_token.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ def initialize(attributes = {})
2121
self.auth_time = auth_time.to_i unless auth_time.nil?
2222
end
2323

24-
def verify!(expected = {})
24+
def verify!(expected = {}, skip_issuer = false)
2525
raise ExpiredToken.new('Invalid ID token: Expired token') unless exp.to_i > Time.now.to_i
26-
raise InvalidIssuer.new('Invalid ID token: Issuer does not match') unless iss == expected[:issuer]
26+
raise InvalidIssuer.new('Invalid ID token: Issuer does not match') unless (iss == expected[:issuer] || skip_issuer == true)
2727
raise InvalidNonce.new('Invalid ID Token: Nonce does not match') unless nonce == expected[:nonce]
2828

2929
# aud(ience) can be a string or an array of strings

spec/openid_connect/response_object/id_token_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@
7979
end
8080
end
8181

82+
context 'when issuer is invalid and skip_issuer is set' do
83+
it do
84+
expect do
85+
id_token.verify!({
86+
issuer: 'invalid_issuer',
87+
client_id: attributes[:aud]},
88+
false
89+
)
90+
end.to raise_error OpenIDConnect::ResponseObject::IdToken::InvalidToken
91+
end
92+
end
93+
8294
context 'when issuer is missing' do
8395
it do
8496
expect do

0 commit comments

Comments
 (0)