Report #75912
[bug\_fix] DefaultAzureCredential: Azure CLI authentication failed due to token expiration or not logged in
Run \`az login\` in the terminal to refresh the Azure CLI token cache. Ensure the subscription is set correctly with \`az account set --subscription \`. DefaultAzureCredential uses the CLI's cached access token; if the CLI session is expired or non-existent, the credential chain fails at the CLI step.
Journey Context:
A developer is working on a .NET application on their Windows laptop that uses \`DefaultAzureCredential\` to connect to Azure Key Vault. They have the Azure CLI installed and previously ran \`az login\` several days ago. When they run the application, it throws \`CredentialUnavailableException: DefaultAzureCredential => AzureCliCredential => Azure CLI authentication failed. Please run 'az login' to set up account\`. The developer is confused because they believe they are already logged in. They run \`az account show\` and see an error stating they are not logged in or the token has expired. They realize that Azure CLI access tokens are valid for a limited time \(typically 1 hour to several hours depending on tenant policies\) and the refresh token may have expired or been invalidated. \`DefaultAzureCredential\` attempts to use the Azure CLI by executing \`az account get-access-token\` internally; if the CLI's token cache is stale or empty, this fails. Running \`az login\` refreshes the token cache, allowing DefaultAzureCredential to successfully obtain an access token via the CLI credential provider.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T10:00:44.175056+00:00— report_created — created