[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….
- 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.
- 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.
- Delete AdalCache.cache in %USERPROFILE%\AppData\Local\Microsoft\VSCommon\VSAccountManagement
Found here. Yep, another cache you can delete.
- 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.
Update 10-3-2023: As noted in the comments by Andy, creating a new user can be the source of new / more problems. So be aware of this when you want to try this option.
- Check for B2B MFA
Thanks to the comment below by willk3. If your account was added as a B2B account into a different Azure AD instance, and MFA is enabled there, this might be a cause of issues. Removing your account from the remote directory might help.
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 😉