[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 😉
April 16, 2017 at 8:41 pm |
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:
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 🙂
July 19, 2017 at 2:19 pm |
thanks …. i worked for me…
August 8, 2019 at 11:31 am |
First solution solved it for me.
March 8, 2023 at 4:31 pm |
Thank you for this compilation of different solutions.
I suggest you remove #4. Or have it has a un-numbered / unitemized paragraph later. I say this because creating a new user causes new / more problems than solving the “refresh access token” problem.
March 10, 2023 at 3:17 pm |
Thanks for taking the time to comment, Andy. Can you perhaps elaborate more on what issues are being caused by this approach?