Why DefaultAzureCredential Fails After az login --tenant (and How to Fix It)
Since Azure Identity 1.11.0, credentials restrict token acquisition to their configured tenant. Here's what breaks and how to fix it.
When working with Azure SDK for Python, you might use DefaultAzureCredential for a seamless authentication experience. However, a common frustration is seeing it fail to acquire a token even after you’ve run az login --tenant <tenant-id> to authenticate via the Azure CLI. In this post, I’ll explain why this happens and how to fix it, covering the inner workings of DefaultAzureCredential, multi-tenant pitfalls and the additionally_allowed_tenants setting.
How DefaultAzureCredential Works
DefaultAzureCredential is an authentication chain that tries multiple credential types in a predefined order to obtain an Azure AD token. It’s designed to work both in cloud environments and on on prem-machines. In simplified terms, when you call DefaultAzureCredential(), it will attempt the following credentials in order:
- Environment Credentials — Checks if environment variables (like AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET) are set for a service principal or user credentials.
- Workload Identity: Applicable in environments where Azure Workload Identity is configured, such as Kubernetes clusters with Azure AD integration.
- Managed Identity — If running on an Azure VM, App Service, or Function with a managed identity, it will attempt the managed identity login.
- Shared Token Cache — Uses any cached credentials from developer tools (e.g. VisualStudioCredential, VisualStudioCodeCredential) that support single sign-on.
- Azure CLI: Leverages the identity from the Azure CLI (az login).
- Azure Powershell: Utilizes the identity from Azure PowerShell (Connect-AzAccount).
- Azure Developer CLI: Employs the identity from the Azure Developer CLI
- Interactive (in some cases) — If all else fails (and if enabled), it may prompt via browser for interactive login.

The Challenge: Multi-Tenant Authentication
Encountering the following error indicates a multi-tenant authentication issue:
DefaultAzureCredential failed to retrieve a token from the included credentials.
...
The current credential is not configured to acquire tokens for tenant <OTHER_TENANT_ID>.
To enable acquiring tokens for this tenant, add it to the additionally_allowed_tenants when creating the credential,
or add "*" to additionally_allowed_tenants to allow acquiring tokens for any tenant.
This occurs because, starting with Azure Identity library version 1.11.0, credentials are restricted from acquiring tokens for tenants other than the one they’re configured for, unless explicitly permitted.
For instance, if you’ve authenticated to Tenant B using Azure CLI (az login --tenant <tenant-id>), but your DefaultAzureCredential is initialized without specifying Tenant B, the library will block token requests for Tenant B by default. This safeguard prevents unintended cross-tenant access.
Diagnosing the Issue
The core problem is that DefaultAzureCredential obtains a token from the authentication chain, but it's not for the intended tenant — even though it may have access to it. Simply running az login --tenant <tenant-id> doesn't resolve this, as the credential chain might still prioritize other credentials associated with different tenants.
There are three ways to solve this:
1. Specify additionally_allowed_tenants
When initializing DefaultAzureCredential, you can permit it to acquire tokens for additional tenants:
from azure.identity import DefaultAzureCredential
credential = DefaultAzureCredential(additionally_allowed_tenants=["*"])
2. Exclude Specific Credentials
If certain credentials in the chain are causing conflicts, you can exclude them:
credential = DefaultAzureCredential(exclude_shared_token_cache_credential=True)
This approach prevents DefaultAzureCredential from using the SharedTokenCacheCredential, which might be associated with a different tenant.
3. Use a Specific Credential
For more control, directly use a specific credential like AzureCliCredential:
from azure.identity import AzureCliCredential
credential = AzureCliCredential()