Azure.Identity.CredentialUnavailableException: EnvironmentCredential authentication unavailable

Tianqi Zhang 0 Reputation points Microsoft Employee
2023-01-11T09:49:12.42+00:00

Our Azure Function is using managed identity and we are getting random error as below. Sometimes it can work but sometimes get /msi/token/ is returning 500.

Azure.Identity.CredentialUnavailableException: EnvironmentCredential authentication unavailable. Environment variables are not fully configured. See the troubleshooting guide for more information. https://aka.ms/azsdk/net/identity/environmentcredential/troubleshoot
at Azure.Identity.CredentialDiagnosticScope.FailWrapAndThrow(Exception ex, String additionalMessage)
at Azure.Identity.EnvironmentCredential.GetTokenImplAsync(Boolean async, TokenRequestContext requestContext, CancellationToken cancellationToken)
at Azure.Identity.EnvironmentCredential.GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken)
at Azure.Identity.DefaultAzureCredential.GetTokenFromSourcesAsync(TokenCredential[] sources, TokenRequestContext requestContext, Boolean async, CancellationToken cancellationToken)

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,798 questions
{count} votes

1 answer

Sort by: Most helpful
  1. 2023-01-12T18:17:19.3166667+00:00

    The EnvironmentCredential authentication unavailable error from within an Azure Function app can be mitigated disabling environment credentials or replacing any DefaultAzureCredential class instance with one of ManagedIdentityCredential.

    To disable environment credentials:

    new DefaultAzureCredential(new DefaultAzureCredentialOptions { ExcludeEnvironmentCredential = true });

    Let us know if you need additional assistance. If the answer was helpful, please accept it and complete the quality survey so that others can find a solution.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.