I think my access token for my scratch org expired. I'm using sfdx in visual studio code. What's the easiest way to get/fresh my access token?
If reauthorizing doesn't help for some reasons(as I was facing) try deleting the alias as follows. It should definitely work
Step 1. Go to /home/.sfdx (In windows c:\user\.sfdx)
Step 2. Delete org specific json file(ORG_USERNAME.json).
Step 3. Edit alias.json file and remove the alias.
Step 4. Restart VS Code and reauthorize.
The easiest way to refresh the access token is just to open the scratch org via Salesforce DX.
From the command palette, you can do
> SFDX: Open Default Org. Or, from the integrated terminal, do
-u my_scratch_alias to select a specific org.
Once you do so, any other functionality you might use that depends on getting an access token via SFDX should work again, provide the scratch org is not expired.
Today I was facing the same issue and I am using vscode on Ubuntu 20. I don't know if it's a bug on vscode or what, but what I did was re-authenticate (SFDX: Authorize and Org) then closed the app and opened again and now it's working. Because I was re-authenticating and not closing the app it wasn't working and I kept re-authenticating a couple more times until I decided to close the app and open again. I hope it helps!
Again log in using force:auth:web:login:
sfdx force:auth:web:login -d -a <alias> -r [<https://test.salesforce.com>,<https://login.salesforce.com>]
-dwill set the authenticated org as the default Dev Hub org.
-asets the alias for the authenticated org (e.g. "qa", "uat", "dev")
--instanceurlis the URL you want to authenticate with.
It is because you might have Authorized the same org twice or more with the same username and alias,
VS Code is a static entity that picks auth info from your folder: c:\user\.sfdx, and it will try to re-auth from old info (if it founds multiple)
that's why it is giving the auth error every time or sometimes (behavior is irregular).
please resolve all duplicates from your folder "c:\user\.sfdx" and they try again. it will work definitely.
PS: Files need to modify
- alias - remove all multiple aliases if any
- remove all username.json files from this folder
- Try to re-authenticate org