function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
miguelmmiguelm 

VS Code Authorizing an Org: authentication failure

Hello!
I created a new project with manifest in VS Code, but I am not able to authorize an Org(sandbox) to it. When I run:

sfdx force:auth:web:login --setalias <alias> --instanceurl <sanboxURL> --setdefaultusername

, it opens the authentication screen, then I insert login + password and it redirects me to localhost:1717 with the following error: 

Error authenticating with auth code due to: authentication failure
This is most likely not an error with the Salesforce CLI. Please ensure all information is accurate and try again.

,in vsc it shows me the following error:

ERROR running auth:web:login:  Invalid client credentials. Verify the OAuth client secret and ID. Error authenticating with auth code due to: authentication failure

VS Code Version: 1.56.2
SFDX CLI Version: sfdx-cli/7.102.0 win32-x64 node-v16.1.0
Salesforce Extension Pack: 51.14.0
 
Best Answer chosen by miguelm
miguelmmiguelm
Problem solved, it was connection error

All Answers

ShivankurShivankur (Salesforce Developers) 
Hi Miguel,

Check out with below thread if it helps you resolve the issue you are facing:
https://developer.salesforce.com/forums/?id=9060G000000MVBsQAO

Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Thanks.
Vishnu SanthoshVishnu Santhosh

Hi Miguel,

Check this Solution from @Vishesh Maskey (https://developer.salesforce.com/forums/?id=9062I000000IDtcQAG)

After working with Salesforce Support, I was able to fix my issue using this article (https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_cli_env_variables.htm) below. I am not sure we can assign a port, it will basically redirect back to 1717. On the article all you do is add a new Environment Variable as described at the bootom of the page on the article and it worked. 

Add Environment Variable NODE_TLS_REJECT_UNAUTHORIZED with a Value of 0

Try this way too. Open your project and Try using the command pallette . Press (Ctrl + Shif + P) or Go to View > Command Pallette.
Type 'Authorize an org' > Select Sandbox > Type an Alias or any name > then you will taken to authorize in a browser. Login and you should be good to go. Try logging in sandbox in the same browser prior of doing all these steps which will make it easy.

Hope you find your solution quickly. Do Mark this suggestion as Best Answer if it helps.

Thank you

miguelmmiguelm
Hi Shivankur,
I had already tried the solution of that post, in the first step sfdx force:auth:web:login it already returns the error:
ERROR running auth:web:login:  Invalid client credentials. Verify the OAuth client secret and ID. Error authenticating with auth code due to: retry your request
miguelmmiguelm
Hi Swetha,
I have nothing running on port 1717
ShivankurShivankur (Salesforce Developers) 
Hi Miguel,

Can you post the exact CLI command which you are trying to run in this thread to check?

Its been also found that the problem could be using lightning.force.com domain instead of my.salesforce.com.

Thanks.
miguelmmiguelm
sure
sfdx force:auth:web:login --setalias devOrg --instanceurl https://geamanagement--dev2.my.salesforce.com/ --setdefaultusername
miguelmmiguelm
Problem solved, it was connection error
This was selected as the best answer
Prachi Gadewar SFDCPrachi Gadewar SFDC
@miguelm,

What is mean by connection error? I am receiving same error, although i never received such error, and therefore wanted to know what made you fix this?
Caleb Kuester 44Caleb Kuester 44
I was able to solve this problem when I encountered it.

What was giving me an error:
sfdx auth:web:login --setalias mysfdxorgalias
What allowed me to log in:
sfdx auth:web:login --setalias mysfdxorgalias --instanceurl https://my-instance-url

I believe that the reason it failed originally was because my logins were defaulted to production, which is a little like trying to log into a sandbox with login.salesforce.com. It just wouldn't work. So when I attempted the sfdx login and then change my domain to the proper instance URL and then give the proper sandbox credentials, I encountered the failure listed in the original post.
Rafael Guerra 17Rafael Guerra 17
Hello people

None of the above information worked for me!

I solved it as follows by putting YES!

https://NAMEORG--hotfix.sandbox.my.salesforce.com/
Lee Khen 25Lee Khen 25
This one worked for me.
Thanks !
Puja Priya 1Puja Priya 1
I was able to resolve this error. The issue was due to using lightning.force.com domain instead of my.salesforce.com in the URL.
Sahana BhattacharyaSahana Bhattacharya
Using custom url option with salesforce classic login url solved the issue for me.
Here's what I did
1. Login to salesforce org
2. Switch view to salesforce classic from "view profile" option at the top right corner
3. Log out (click on user name)
4. Copy the url from logged out page
5. Use this url in the Custom option while Authorizing an org
Example: https://<domain-name>.my.salesforce.com