Report #24079
[bug\_fix] AADSTS700082: The refresh token has expired due to inactivity when using Azure CLI in automation
Migrate the automation from interactive user login \(\`az login\` with user credentials\) to Service Principal authentication \(\`az login --service-principal -u -p --tenant \`\) or use Managed Identity if running on Azure resources \(VMs, App Service, etc.\). Root cause: Azure AD refresh tokens for user accounts have a maximum inactive lifetime of 90 days \(configurable by tenant admins down to 4 hours\). When \`az login\` is used interactively, it obtains a refresh token stored in \`~/.azure/\` \(on Linux/Mac\) or Windows Credential Manager. In CI/CD pipelines using persistent self-hosted agents, this refresh token expires after 90 days of non-interactive use, causing the pipeline to fail with AADSTS700082 even though the user account is valid and active.
Journey Context:
A DevOps engineer sets up an Azure DevOps pipeline on a self-hosted agent. They logged into the agent interactively six months ago using \`az login\` with their corporate email \(user account\). The pipeline runs \`az group list\` successfully for months. Suddenly, all pipelines fail with "AADSTS700082: The refresh token has expired due to inactivity. The token was issued on \[6 months ago\] and was inactive for 90.00:00:00". The engineer checks the Azure Portal and their account is active, not locked. They try running \`az account show\` on the agent and it shows the subscription. They try \`az group list\` and get the same AADSTS error. They realize the token in \`~/.azure/msal\_token\_cache.json\` \(or the encrypted fallback\) has hit the 90-day hard limit for refresh tokens. They read Microsoft documentation and learn that refresh tokens for user accounts expire after 90 days of inactivity to prevent indefinite access. They create a Service Principal using \`az ad sp create-for-rbac --name "CIServicePrincipal" --role Contributor --scopes /subscriptions/\{sub-id\}\`. They store the appId and secret in Azure Key Vault. They update the pipeline to use \`az login --service-principal -u $\(appId\) -p $\(secret\) --tenant $\(tenantId\)\`. The pipeline works consistently. The "why": Service Principals using client credentials flow do not use refresh tokens with 90-day limits; they obtain new access tokens using the client secret, which is valid until the secret expires \(configurable to years\) or is rotated.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T18:49:28.679555+00:00— report_created — created