10
10
from .._internal import AsyncContextManager
11
11
from ... import CredentialUnavailableError
12
12
from ..._credentials .chained import _get_error_message
13
+ from ..._internal import within_credential_chain
13
14
14
15
if TYPE_CHECKING :
15
16
from typing import Any , Optional
@@ -52,6 +53,7 @@ async def get_token(self, *scopes: str, **kwargs: "Any") -> "AccessToken":
52
53
:param str scopes: desired scopes for the access token. This method requires at least one scope.
53
54
:raises ~azure.core.exceptions.ClientAuthenticationError: no credential in the chain provided a token
54
55
"""
56
+ within_credential_chain .set (True )
55
57
history = []
56
58
for credential in self .credentials :
57
59
try :
@@ -62,19 +64,19 @@ async def get_token(self, *scopes: str, **kwargs: "Any") -> "AccessToken":
62
64
except CredentialUnavailableError as ex :
63
65
# credential didn't attempt authentication because it lacks required data or state -> continue
64
66
history .append ((credential , ex .message ))
65
- _LOGGER .info ("%s - %s is unavailable" , self .__class__ .__name__ , credential .__class__ .__name__ )
66
67
except Exception as ex : # pylint: disable=broad-except
67
68
# credential failed to authenticate, or something unexpectedly raised -> break
68
69
history .append ((credential , str (ex )))
69
- _LOGGER .warning (
70
+ _LOGGER .debug (
70
71
'%s.get_token failed: %s raised unexpected error "%s"' ,
71
72
self .__class__ .__name__ ,
72
73
credential .__class__ .__name__ ,
73
74
ex ,
74
- exc_info = _LOGGER . isEnabledFor ( logging . DEBUG ) ,
75
+ exc_info = True ,
75
76
)
76
77
break
77
78
79
+ within_credential_chain .set (False )
78
80
attempts = _get_error_message (history )
79
81
message = self .__class__ .__name__ + " failed to retrieve a token from the included credentials." + attempts
80
82
raise ClientAuthenticationError (message = message )
0 commit comments