I had an unhandled exception when calling PersistentAuthHelper.GetToken(string id, string resource) to log into an Azure subscription which I hadn't accessed in a very long time. Unfortunately I didn't document the details (or locate and back up the token cache) before trying a workaround, but the gist was that BaseAuthHelper.GetTokenInternal went into the case
|
if (cacheInfo.ExpiresOn <= DateTimeOffset.UtcNow) |
which called
|
return await GetAuthorizationResultByRefreshToken(tokenCache, cacheInfo); |
and that threw an exception on receiving an HTTP 400 response because the refresh token was too old.
A workaround is to change
|
if (ex.Message.IndexOf(" is expired") < 0) |
to
if (ex.Message.IndexOf(" is expired") < 0 && ex.Message.IndexOf(" has expired") < 0)
but I suspect that a better solution would be to rework the logic of GetTokenInternal so that it treats a cache entry older than some cutoff (90 days?) as non-existent.
I had an unhandled exception when calling
PersistentAuthHelper.GetToken(string id, string resource)to log into an Azure subscription which I hadn't accessed in a very long time. Unfortunately I didn't document the details (or locate and back up the token cache) before trying a workaround, but the gist was thatBaseAuthHelper.GetTokenInternalwent into the caseARMClient/ARMClient.Authentication/AADAuthentication/BaseAuthHelper.cs
Line 318 in 3dc4ff9
which called
ARMClient/ARMClient.Authentication/AADAuthentication/BaseAuthHelper.cs
Line 442 in 3dc4ff9
and that threw an exception on receiving an HTTP 400 response because the refresh token was too old.
A workaround is to change
ARMClient/ARMClient.Authentication/AADAuthentication/BaseAuthHelper.cs
Line 257 in 3dc4ff9
to
but I suspect that a better solution would be to rework the logic of
GetTokenInternalso that it treats a cache entry older than some cutoff (90 days?) as non-existent.