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?
7 Answers
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.
-
I was facing same issue. sfdx force:org:list had expired token, sfdx force:auth:web:login refreshed it, but couldn't log in. This clear then sfdx force:auth:web:login worked well for me. Sep 1, 2021 at 15:35
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
sfdx force:org:open
optionally with -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.
-
2
-
1Are you certain that the scratch org is not expired? Could you show in your question the output of
sfdx force:org:list
?– David Reed ♦Mar 25, 2019 at 15:22 -
-
-
This is happening every other day to me now. The org does not appear in force:org:list anymore, nor does org:open help. When I do a force:org:delete this command works - but I cannot access the scratch org anymore :( (Also tried manual login) Apr 3, 2020 at 5:34
These steps in Visual Studio Code will fix the issue,
Step1: In the command palette SFDX: Authorize an Org
Step2: Enter alias name (example: lwc_sandbox
)
Step3: Login into your Org from the default browser
Authorization Success and Token expired issue will be fixed.
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>]
-d
will set the authenticated org as the default Dev Hub org.-a
sets the alias for the authenticated org (e.g. "qa", "uat", "dev")-r
or--instanceurl
is the URL you want to authenticate with.
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!
-
please read my latest answer, it might solve your problem Jan 11, 2022 at 12:59
-
ABSOLUTE SOLUTION
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).
solution:
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
Enjoy :)
This solution works every time.
- Run SFDX:Authorize an Org. Use the same Alias as you did when you initially setup the org.
- Restart VsCode
Your deploy/retrieve will now succeed.