@@ -67,6 +67,7 @@ def __init__(
6767 performed.
6868 """
6969 self ._http_client = http_client
70+ self ._oidc_authority_url = oidc_authority_url
7071 if oidc_authority_url :
7172 logger .debug ("Initializing with OIDC authority: %s" , oidc_authority_url )
7273 tenant_discovery_endpoint = self ._initialize_oidc_authority (
@@ -95,6 +96,7 @@ def __init__(
9596 raise ValueError (error_message )
9697 logger .debug (
9798 'openid_config("%s") = %s' , tenant_discovery_endpoint , openid_config )
99+ self ._issuer = openid_config .get ('issuer' )
98100 self .authorization_endpoint = openid_config ['authorization_endpoint' ]
99101 self .token_endpoint = openid_config ['token_endpoint' ]
100102 self .device_authorization_endpoint = openid_config .get ('device_authorization_endpoint' )
@@ -174,11 +176,24 @@ def user_realm_discovery(self, username, correlation_id=None, response=None):
174176 self .__class__ ._domains_without_user_realm_discovery .add (self .instance )
175177 return {} # This can guide the caller to fall back normal ROPC flow
176178
179+ def is_valid_issuer (self ) -> bool :
180+ if self ._oidc_authority_url :
181+ return self ._oidc_authority_url == self ._issuer
182+ else :
183+ # The non-OIDC cases include:
184+ # those known-to-Microsoft, those known-to-developer,
185+ # those already passed authority validation, or those opted out of authority validation.
186+ # TODO: We plan to remove the OIDC discovery behavior in the near future.
187+ # Then we can simply return True here.
188+ return True
189+
177190
178191def canonicalize (authority_or_auth_endpoint ):
179192 # Returns (url_parsed_result, hostname_in_lowercase, tenant)
180193 authority = urlparse (authority_or_auth_endpoint )
181- if authority .scheme == "https" :
194+ if (
195+ authority .scheme == "http" and authority .hostname in ("localhost" , "127.0.0.1" )
196+ ) or authority .scheme == "https" :
182197 parts = authority .path .split ("/" )
183198 first_part = parts [1 ] if len (parts ) >= 2 and parts [1 ] else None
184199 if authority .hostname .endswith (_CIAM_DOMAIN_SUFFIX ): # CIAM
0 commit comments