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
Lokesh Krishna SagiLokesh Krishna Sagi 

VS Code - localhost 1717 error while Authorizing an Org

Hi All,

I am trying to authorize an org (Dev org not sandbox) from VS Code and I am in my Company network and default port Id 1717 wouldnt work for me. I have followed the below steps to create a Connected App and change port number in sfdx-project.json file. But still its taking me to old 1717 localhost even after changin the port number.

From Connected App..
User-added image

From VSCode project setup..

User-added image

I have also tried to put 443 in the redirected URL instead of 1717. But it doesnt work either.

Is there any mistake that I have done while setting up the Conncted App ? BTW, I am not using JWT AUthentication. Its just web based authentication. How else can I change the default port number ?

PS : I have used both "oauthLocalPort" : "443" and "oauthLocalPort" : 443. 
 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Lokesh,

Greetings to you!

Please refer to the below links which might help you further with the above issue.

https://salesforce.stackexchange.com/questions/208158/authorizing-dev-hub-from-force-com-ide2-redirects-to-localhost-after-authorizing

https://salesforce.stackexchange.com/questions/249857/cannot-connect-a-salesforce-org-using-authorize-an-org-in-vs-code

https://salesforce.stackexchange.com/questions/251589/unable-to-authorize-salesforce-org-using-sfdx-trailhead

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Eva He 11Eva He 11
I tried all the solutions above, they were not working for me.
I have been stucked for 2-3 days and finally I pray and have the idea to change to using another browser (from Edge to Chrome, it works).
Thanks Lord Jesus!
Shamsher Khan 5Shamsher Khan 5
Hi  Lokesh Krishna Sagi,

Did your issue got solved. I am facing the same issue from the last few days. It will be great if you can share us the solution if found.

Thanks,
Shamsher
Vishesh MaskeyVishesh Maskey
On the same boat, is there a way to change the Port somewhere else?
Faujiya Mandrupkar 20Faujiya Mandrupkar 20
Yes, I am also facing the same issue. It isn't working at all. Please help!!
Vishesh MaskeyVishesh Maskey

Faujiya,
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

Full link:
https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_cli_env_variables.htm

Hope this helps ya.

ANUTEJANUTEJ (Salesforce Developers) 
Hi Lokesh,

I see that you are getting the above error while authenticating the org.

Can you try adding the below line project.json file and try it.

"oauthLocalPort" : "1919"

Kindly let me know if this helps.  If it does please close this question by marking a best answer so that it would help others in the future and also helps the community in keeping it clean.

Thanks and Regards,
Anutej Poddaturi
Faujiya Mandrupkar 20Faujiya Mandrupkar 20
Hi Vishesh,

Thank you for your reply. I had already tried that option but it didn;t work either. I got my chrome recently updated to 80 version and it was my default browser. I changed my default browser to IE and it started working for me. After almost 5 days, finally got it working by changing the default browser to IE. (it might work with Edge too, but I have not tried it).

Regards,
Faujiya Mandrupkar
Faujiya Mandrupkar 20Faujiya Mandrupkar 20
Also, just to add to my previous comment this issue occurs when we are Authorizing the org and the command runs forever. We can create project successfully though. And to resolve the 1717 issue you can run netstat -aon command in cmd as Admin, find the 1717 string by using Ctrl+f and then check the PID number(for eg: 7689) against the 1717. Kill the process with using taskkill /pid 7689 /f (replace the 7689 with your PID). Run the authorize command again in VS code and it will open the salesforce login window. Again do not forget to change your default browser else the command for org authorization will keep running without error.

I hope this helps.

Regards,
Faujiya Mandrupkar
Krishna Kishore 81Krishna Kishore 81

@Vishesh....thanks! it worked for me...

Shruti Suman MishraShruti Suman Mishra
Hi @Lokesh, This issue could be resolved by the solution provided by @Vishesh. Could you please mark his answer and close this to avoid any confusion. Thanks.
sandeep soni 9sandeep soni 9
Hi All,

I faced this issue and resolved:
Error Message: when i was trying to auth org using vs code it was showing below error message:
ERROR running force:auth:web:login: grant type not supported
or
page is redirecting on localhost:1717 and not auth org failed

Solution:
Open Terminal window in MAC, type top, you will see 1717 in that not down PID number that may be 1717, close this terminal
Open another terminal, type below command:
kill -9 1717 Press Enter
The process that’s running on 1717 port will be kill, again authorize your org from vs code, issue will be resolved. 

 
Nikolay Zahariev 9Nikolay Zahariev 9

I had the same using custom domain login

The issue that I have was putting salesforce URL instead of my domain URL while "New Org" VC Code Command
Setup/My Domain
Your domain name is: https://xxx-nzahorg-zxc--cscdev.my.salesforce.com  

https://xxx-nzahorg-zxc--cscdev.lightning.force.com  - salesforce org - wrong
https://xxx-nzahorg-zxc--cscdev.my.salesforce.com    - mydomian       - correct 

akashdeeparoraakashdeeparora
To recover from a failed org authorization on Windows, use the Task Manager to end the Node process.
 
Press Ctrl+Alt+Delete, then click Task Manager.
Select the Process tab.
Find the process named Node.
 
Note
If you’re a Node.js developer, you might have several running processes with this name.
 
Select the process that you want to end, and then click End Process.

#LCAnswers #BeASalesforceChamp
Dinesh MengadeDinesh Mengade
changing default browser to different e.g Edge, firefox solves my issue.
Rahul Jangir 2Rahul Jangir 2
Hi Lokesh Krishna Sagi,

Authorize your org with a custom URL from VS code using salesforce's classic URL. It will definitely work.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved.


Thanks and Regards,
Rahul Jangir
chen huanchongchen huanchong

I hope it helps you.
1 . JAVAHOME set

User-added imageUser-added image
User-added image

2. Run command in the terminal 
    sfdx plugins:install @salesforce/plugin-auth@1.4.3

3. Run command in the terminal 
    sfdx auth:web:login --setalias myOrg --instanceurl https://login.salesforce.com --setdefaultusername

jegadeesh grjegadeesh gr
Nikolay Zahariev You are correct. That's the issue for me. 
Matheus Campos 15Matheus Campos 15
Hi people, I can resolve this problem uninstall the "Salesforce CLI" on control panel, and after this I install again, I hope this resolve the problem of everyone, I passed all my day trying to resolve this problem, this is really hard.... tks for all the help. bye.
Jamie BrowningJamie Browning

None of the solutions above work, nor should they be used.

Salesforce CLI is just broken,

So until Salesforce fix it use:

 

sfdx auth:device:login -a MyAlias -r https://<mydomain>--<sandbox>.my.salesforce.com -s

 

Łukasz LelakowskiŁukasz Lelakowski
Matheus Campos 15, your solution worked for me, thanks!!
Miguel Delgado Ventas 7Miguel Delgado Ventas 7

chen huanchong, that work fine form mi. Thanks very much.
John John Howard SellersJohn John Howard Sellers

@Rahul Jangir 2's solution of using the Classic URL did the trick for me. Thanks Rahul
Sarang GhodeSarang Ghode
Hi, I am not able to connect to localhost:1717 while I am trying to authorise the org in VS code. The error shown on Internet explorer is "Can’t reach this page Make sure the web address http://localhost:1717 is correct" 
Troy CenterTroy Center

WINDOWS PC Only... (don't use taskmanager!)

Using VSCode, open a new "cmd" terminal
OR Using Command Prompt for Windows (Click start, type "cmd" press enter)

1) c:\ netstat -ano | findstr :1717
-a = Displays all connections and listening ports.
-n = Displays addresses and port numbers in numerical form.
-o = Displays the owning process ID associated with each connection.

2) c:\ taskkill /PID [YOUR PID] /F
/F = Specifies to forcefully terminate the process(es).

Screenshot of taskkill
3) Press F1 and do SFDX: Authorize an Org. 
Wait for the CLI to pop up and ask questions, don't interrupt it. Name your connection and GO! It should work now. 

Note about sfdx_project.json:
I recommend using your mydomain name for the sfdcLoginUrl in the sfdx-project.json file. Just make sure you get it from Classic, not Lightning. It should look like this:  "sfdcLoginUrl": "https://corpadefakeo-sandbox1.my.salesforce.com". 

Christopher Johnson 15Christopher Johnson 15

Speaking to windows here, the root cause of this issue is port exclusion by the WINNAT service (winnat randomly reserves some ports and disallows use by other processes). If WINNAT is not configured to leave port 1717 alone, it will randomly hold it (held ports can change with each reboot of your PC, causing the issue to appear random, or to fix after a reboot).

Run this command from a cmd prompt to see if port 1717 is being held by WINNAT:
netsh interface ipv4 show excludedportrange protocol=tcp

The command above will give output like this, in this case 1717 is between 1684 and 1783, so I am affected by the issue:
Start Port    End Port
----------    --------
        80          80
      1025        1124
      1545        1644
      1683        1683
      1684        1783
      1784        1883
      1884        1983
      1984        2083

If  it is, you have to stop the winnat service, exclude port 1717, and restart it using these commands (admin command prompt):
1)
net stop winnat
2)
netsh int ipv4 add excludedportrange protocol=tcp startport=1717 numberofports=1
3)
net start winnat

After running those commands, try your "SFDX: Authorize an Org" again.

 

Root cause of this issue is node.js not using a properly reserved port for oAuth (1717) (SFDX uses node.js for oAuth processes as I understand it), but rather using a random port that just happens to be reserved by Microsoft (Microsoft Convoy).

Rahul Joshi 2Rahul Joshi 2
Everytime I try configuring VS Code I get a new problem. This must be my 7th or 8th time installing over many years.

Error URL:
localhost:1717/OauthRedirect?error=OAUTH_APP_BLOCKED&error_description=this+app+is+blocked+by+admin&state=eefcbed43edd

Error Description: 
this app is blocked by admin
This is most likely not an error with the Salesforce CLI. Please ensure all information is accurate and try again.

Solution: Go to your sandbox to Connected Apps and Unblock the 'Salesforce CLI' App. Refer screenshot. This resolved the Salesforce CLI issue I was facing. 


User-added image
Sahana BhattacharyaSahana Bhattacharya

Using custom url option with salesforce classic login url solved the issue for me. Thanks Rahul Jangir.

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

Suhas JainSuhas Jain

Below is what worked for me 

Updated the port as below to some unused port in sfdx-project.json (Found in each project in the main directory)

"oauthLocalPort": 7714

made sure this port is not being used (by running the command "top" in mac os). 

used the command.     sfdx force:auth:web:login -a <alias>  (replace <alias> with your org name)

this will take to authorization after sucessful login. see if the oAuth redirect URL has the same port as the one mentioned in "oauthLocalPort" in sfdx-project.json , if not just replace the port in the URL with the one mentioned in the sfdx-project.json and hit the URL again and Authorization Sucessful !

SrinivasaRao LatchuSrinivasaRao Latchu

1) vscode java.home is set with latest version.
2) Updated the port as below to some unused port in sfdx-project.json (Found in each project in the main directory)
"oauthLocalPort": 1909
3)in new termina sfdx auth:web:login -r https://<MyDomainName>--<SandboxName>.sandbox.my.salesforce.com

4) This will take to authorization after sucessful login. see if the oAuth redirect URL has the same port as the one mentioned in "oauthLocalPort" in sfdx-project.json , if not just replace the port in the URL with the one mentioned in the sfdx-project.json and hit the URL again and Authorization Sucessful if not take leave for today :)