1010from .._internal import AsyncContextManager
1111from ... import CredentialUnavailableError
1212from ..._credentials .chained import _get_error_message
13+ from ..._internal import within_credential_chain
1314
1415if TYPE_CHECKING :
1516 from typing import Any , Optional
@@ -52,6 +53,7 @@ async def get_token(self, *scopes: str, **kwargs: "Any") -> "AccessToken":
5253 :param str scopes: desired scopes for the access token. This method requires at least one scope.
5354 :raises ~azure.core.exceptions.ClientAuthenticationError: no credential in the chain provided a token
5455 """
56+ within_credential_chain .set (True )
5557 history = []
5658 for credential in self .credentials :
5759 try :
@@ -62,19 +64,19 @@ async def get_token(self, *scopes: str, **kwargs: "Any") -> "AccessToken":
6264 except CredentialUnavailableError as ex :
6365 # credential didn't attempt authentication because it lacks required data or state -> continue
6466 history .append ((credential , ex .message ))
65- _LOGGER .info ("%s - %s is unavailable" , self .__class__ .__name__ , credential .__class__ .__name__ )
6667 except Exception as ex : # pylint: disable=broad-except
6768 # credential failed to authenticate, or something unexpectedly raised -> break
6869 history .append ((credential , str (ex )))
69- _LOGGER .warning (
70+ _LOGGER .debug (
7071 '%s.get_token failed: %s raised unexpected error "%s"' ,
7172 self .__class__ .__name__ ,
7273 credential .__class__ .__name__ ,
7374 ex ,
74- exc_info = _LOGGER . isEnabledFor ( logging . DEBUG ) ,
75+ exc_info = True ,
7576 )
7677 break
7778
79+ within_credential_chain .set (False )
7880 attempts = _get_error_message (history )
7981 message = self .__class__ .__name__ + " failed to retrieve a token from the included credentials." + attempts
8082 raise ClientAuthenticationError (message = message )
0 commit comments