Distinguish credential unavailability from failure#9372
Distinguish credential unavailability from failure#9372chlowell merged 6 commits intoAzure:masterfrom
Conversation
bryevdv
left a comment
There was a problem hiding this comment.
Great tests, only one small suggestion
There was a problem hiding this comment.
CredentialUnavailableError needs to be a sub-class of ClientAuthenticationError. Or it will be a breaking change.
There was a problem hiding this comment.
ClientAuthenticationError inherits HttpResponseError, which is misleading as a base here because CredentialUnavailableError is raised when no request was sent.
I agree changing the hierarchy is a larger issue. For this PR I'll have CredentialUnavailableError inherit ClientAuthenticationError, and we can revisit the hierarchy later.
xiangyan99
left a comment
There was a problem hiding this comment.
CredentialUnavailableError needs to be a sub-class of ClientAuthenticationError. Or it will be a breaking change.
e186bb5 to
ff5fdfb
Compare
ff5fdfb to
a3da347
Compare
a3da347 to
a663546
Compare
This adds
CredentialUnavailableErrorto indicate a credential didn't attempt to authenticate because it lacks required data or state. For example,EnvironmentCredentialraises it when environment configuration is incomplete, andSharedTokenCacheCredentialraises it when the shared cache isn't present. Credentials previously raisedClientAuthenticationErrorin such cases. That exception now indicates a credential attempted to authenticate but failed due to an unexpected error.ChainedTokenCredential(andDefaultAzureCredential) uses this to make authentication more predictable. When one of its credentials raises,ChainedTokenCredentialonly tries the next credential when the raised exception isCredentialUnavailableError. This prevents unexpected authentication. For example, if environment variables specify a service principal with an invalid secret,DefaultAzureCredentialwon't continue on to managed identity after authenticating as that principal fails.Closes #8166