Skip to content

Unhandled case: renewal fails because the token is too old #49

@pjt33

Description

@pjt33

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions