I recently refreshed my developer sandbox.
In VS Code, I ran
sfdx force:auth:web:login --setalias aliasName --instanceurl https://test.salesforce.com --setdefaultusername
It opened the OAuth window and I logged in. I noted that I wasn't prompted to grant access permission to SFDX cli, nor do I see such an app in the sandbox's app manager.
Back in VS code, if I run
sfdx force:org:display --targetusername aliasName
I get an org description of my sandbox the a Connected Status of 'Connected'. If I run
sfdx force:org:open, my sandbox opens in browser.
When I open the context menu on files in my local repo I see options for
SFDX: Deploy Source to Org and
SFDX: Retrieve Source from Org..
And yet, when I attempt either one of these, I get the following error:
'Error authenticating with the refresh token due to: expired access/refresh token'
If I had to guess this has to do with me not having a proper connected app set up in my sandbox, but I'm not sure what step to take other than authorizing the org through SFDX. What am I missing?
August 2023 Update: If you're coming here at this point, I'm guessing you haven't yet gotten off SFDX and onto SF, the new CLI space that Salesforce is introducing. They offer instructions on how to uninstall the SFDX CLI and install SF CLI instead, which has its own set of similar commands that will now related to the deploy and retrieve context options you see in VSCode.
So if you're looking to troubleshoot, first step should be to uninstall SFDX and get on the latest version of SF, then retry.