[VS2017] Unable to login “failed to refresh access token”

I was running into this weird error today. For some reason (you know… it happens) Visual Studio lost it’s license. I was still logged in, but requested to re-enter my credentials. So I tried, but I kept getting errors. I then thought: let’s log out and log in again. So yeah, that didn’t happen…

The error I got was: “We could not refresh the credentials for the account. Failed to refresh access token.”. Refresh token refers to something that I know from OAuth authentication; being a token that you can use to get new authentication tokens after old ones expire. Ok so why was it not refreshing?

My Google search quest led me to a couple of answers. I’ll list them here for your convenience. One might work, the other might not based on the underlying issue your having. But chances are at least one of these solutions will work for you. I’ll start with the most important one; the one that fixed it for me….

  1. Delete %LOCALAPPDATA%\.IdentityService
    Found here, simply delete the entire folder. There seems to be some identity related caching going on in there, deleting the folder will force the identity system to rebuild its cache and that seems to have fixed it.
  2. Delete everything under regkey: Computer\HKEY_CURRENT_USER\Software\Microsoft\VSCommon\ConnectedUser
    Found here, this is a similar solution as there again is some logging info cached in that particular registry section.
  3. Delete AdalCache.cache in %USERPROFILE%\AppData\Local\Microsoft\VSCommon\VSAccountManagement
    Found here. Yep, another cache you can delete.
  4. Add a second user account to Visual Studio
    I didn’t actually try this, but if you have multiple accounts you could try adding another account, then removing the primary and re-adding it back in. Instructions on how to add a second account are found on this page.

Should you have found anything else that worked for you, feel free to drop it in the comments below and I’ll make sure that this one post rules them all 😉

2 thoughts on “[VS2017] Unable to login “failed to refresh access token”

  1. Hi,

    I ran through the steps in this article, but it wasn’t resolved. To fix this, I downloaded ProcMon from sysinternals and then reproduced the error. I found there is a log file which might produce some hints:

    C:\Users\\AppData\Local\Temp\servicehub\logs\

    AadAccountProviderService

    My issue was that my account had been added as an AzureAD B2B user in another tenant which required MFA. As it turns out there might be a bug currently in MFA.. I removed the user from that remote directory and the problem has gone 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *