Report #15464
[bug\_fix] Azure 'InvalidAuthenticationToken' during long-running operations due to token expiry
Use DefaultAzureCredential with token caching enabled and automatic refresh, or manually implement token refresh before expiry. For CLI scripts, break operations into chunks smaller than the token lifetime \(default 1 hour\) or use 'az account get-access-token' to fetch fresh tokens periodically. Root cause: Azure AD access tokens default to a 1-hour lifetime; long-running uploads or deployments exceed this window, and manually passed tokens are not auto-refreshed by the SDK.
Journey Context:
A developer writes a Python script using the Azure Storage SDK to upload a 500GB file to Blob Storage using 'BlobClient.upload\_blob\(\)'. They authenticate using 'DefaultAzureCredential\(\)' at the start of the script to get a token and pass it to the client. The upload starts but takes 90 minutes due to network speed. At the 65-minute mark, the SDK throws 'azure.core.exceptions.HttpResponseError: 401 Unauthorized. The access token expiry UTC time is earlier than current UTC time'. The developer realizes that the token was fetched once at the start and never refreshed. They modify the code to use 'DefaultAzureCredential' directly as the credential object when constructing 'BlobServiceClient', which internally caches tokens and refreshes them automatically before expiry. Alternatively, they implement a token refresh callback or switch to using Azure CLI's 'az storage blob upload' which handles token lifecycle internally.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:14:18.540229+00:00— report_created — created