@@ -32,7 +32,7 @@ def __init__(
3232 disable_instance_discovery : Optional [bool ] = None ,
3333 tenant_id : Optional [str ] = None ,
3434 enable_support_logging : Optional [bool ] = None ,
35- ** kwargs : Any
35+ ** kwargs : Any ,
3636 ) -> None :
3737 self ._instance_discovery = None if disable_instance_discovery is None else not disable_instance_discovery
3838 self ._authority = normalize_authority (authority ) if authority else get_default_authority ()
@@ -104,17 +104,26 @@ def _get_app(self, **kwargs: Any) -> msal.ClientApplication:
104104 token_cache = self ._initialize_cache (is_cae = bool (kwargs .get ("enable_cae" )))
105105
106106 if tenant_id not in client_applications_map :
107- client_applications_map [tenant_id ] = app_class (
108- client_id = self ._client_id ,
109- client_credential = self ._client_credential ,
110- client_capabilities = capabilities ,
111- authority = "{}/{}" .format (self ._authority , tenant_id ),
112- azure_region = self ._regional_authority ,
113- token_cache = token_cache ,
114- http_client = self ._client ,
115- instance_discovery = self ._instance_discovery ,
116- enable_pii_log = self ._enable_support_logging ,
117- )
107+ try :
108+ client_applications_map [tenant_id ] = app_class (
109+ client_id = self ._client_id ,
110+ client_credential = self ._client_credential ,
111+ client_capabilities = capabilities ,
112+ authority = "{}/{}" .format (self ._authority , tenant_id ),
113+ azure_region = self ._regional_authority ,
114+ token_cache = token_cache ,
115+ http_client = self ._client ,
116+ instance_discovery = self ._instance_discovery ,
117+ enable_pii_log = self ._enable_support_logging ,
118+ )
119+ except ValueError as ex :
120+ if "invalid_instance" in str (ex ):
121+ raise ValueError ( # pylint: disable=raise-missing-from
122+ f"The authority provided, { self ._authority } , is not well-known. If this authority is valid "
123+ "and trustworthy, you can disable this check by passing in "
124+ "'disable_instance_discovery=True' when constructing the credential."
125+ )
126+ raise
118127
119128 return client_applications_map [tenant_id ]
120129
0 commit comments