Report #70338
[bug\_fix] Azure CLI / SDK: "Authentication failed. The refresh token has expired due to inactivity" or "Please run 'az login'"
Run \`az login --tenant \` \(add \`--use-device-code\` on headless/SSH boxes\). For service principals, re-run \`az login --service-principal -u -p --tenant \` or switch to managed identity when running inside Azure. For SDK code using \`DefaultAzureCredential\`, ensure \`AZURE\_TENANT\_ID\` is set and run \`az login\` first.
Journey Context:
Your \`az group list\` call worked last week, but now returns an error telling you the refresh token has expired and to run \`az login\`. You try \`az account show\` and see an account listed, so the account is not missing — the token cache just cannot refresh. You look in \`~/.azure/\` and find \`msal\_token\_cache.json\`; the refresh token's \`expires\_on\` has passed. Azure AD / Microsoft Entra ID issues access tokens with short lifetimes and refresh tokens that can expire or be revoked by conditional-access policies, password changes, or tenant admin settings. When the MSAL cache has no valid refresh token, the Azure CLI cannot silently acquire a new access token. \`az login\` re-negotiates a full OAuth2 code/device-code flow, writes a new refresh token, and restores access. In non-interactive automation, service-principal secrets or managed identities avoid the personal-token expiry problem entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:39:02.223957+00:00— report_created — created