Help with Azure authentication issues and credential management
Diagnoses Azure authentication issues and provides solutions for various login methods.
/plugin marketplace add charris-msft/azure-plugin/plugin install charris-msft-azure-mcp@charris-msft/azure-plugin[issue-description]Diagnose and resolve Azure authentication issues.
az account show 2>&1
Analyze the output:
For users with browser access:
az login
For headless or remote environments:
az login --use-device-code
Instruct user to:
For automated/CI scenarios:
az login --service-principal \
--username <app-id> \
--password <client-secret> \
--tenant <tenant-id>
Required information:
For Azure-hosted environments (VMs, App Service, etc.):
az login --identity
For user-assigned managed identity:
az login --identity --username <managed-identity-client-id>
az account get-access-token --query "expiresOn" -o tsv
If token is expired or expiring soon:
az account get-access-token --resource https://management.azure.com/
If experiencing stale credential issues:
az account clear
az login
az account list --output table
az account set --subscription "<name-or-id>"
az account show --query "{Name:name, ID:id, State:state}" -o table
Cause: Multi-factor authentication is required but not completed.
Solution:
az login --use-device-code
Complete MFA in the browser.
Cause: Service principal doesn't exist or wrong tenant.
Solution:
Cause: Client secret is wrong or expired.
Solution:
Cause: Account has no Azure subscriptions or lacks access.
Solution:
Cause: Cached tokens are corrupted or expired.
Solution:
az account clear
az cache purge
az login
For non-interactive scenarios, set these environment variables:
# Service Principal
export AZURE_TENANT_ID="<tenant-id>"
export AZURE_CLIENT_ID="<client-id>"
export AZURE_CLIENT_SECRET="<client-secret>"
# For Azure MCP Server
# These are read automatically if set
After diagnosing, provide: