Salesforcedx-vscode: SFDX: Authorize an Org (Allow Selection of Org Login Url)

Created on 30 Aug 2018  路  21Comments  路  Source: forcedotcom/salesforcedx-vscode

Summary

Difficult / impossible to follow the wiki:
https://github.com/forcedotcom/salesforcedx-vscode/wiki/Develop-Against-Any-Org-in-Visual-Studio-Code

to Auth to a Sandbox from within VSCode

Steps To Reproduce:

  1. Follow the wiki article
  2. run SFDX: Authorize an Org command in VSCode
  3. enter a sandbox username
  4. it takes you to login.salesforce.com

Expected result

either it intelligently selects the domain, or switching the domain works

Actual result

  • tried using custom domain without much luck
  • tired passing argument -r https://test.salesforce.com without luck

Additional information

VS Code Version:

SFDX CLI Version:

OS and version:

feature

Most helpful comment

@evanmcd The error Unknown config name ... comes from using sfdx force:config:set. You can not use sfdcLoginUrl as a config variable. Instead, that needs to go in your sfdx-project.json file. If you want to set a config var, you can try sfdx force:config:set instanceUrl=https://test.salesforce.com. I think the auth commands will use the following order:

  1. --instanceurl flag on the commands
  2. sfdcLoginUrl in the sfdx-project.json file
  3. instanceUrl in force:config:set
  4. SFDX_INSTANCE_URL envvar

All 21 comments

Agreed. This is a usability issue. We need to work on this to make this simpler.

@JimBTek - For now, could you edit your sfdx-project.json to include " "sfdcLoginUrl": "https://test.salesforce.com".

This is documented at https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_config.htm

@ntotten or @ruthemmanuelle - We probably want to add that to the wiki

Some possible suggestions would be to augment force:project:create --manifest with the template option to be production or sandbox. In the sandbox case then it will add the "sfdcLoginUrl": "https://test.salesforce.com" for you. Then we can augment the VS Code side to make those options available.

Since @ntotten is on vacation this week, I went ahead and updated the wiki to add info on how to update the login URL so you can authorize a sandbox org:

https://github.com/forcedotcom/salesforcedx-vscode/wiki/Develop-Against-Any-Org-in-Visual-Studio-Code/_compare/38076ff10814ede6f0af3df4247f74cc3f354c11...1811ac26ee77acec3e0cff47d8ad0263656ed33b

Thanks for the heads-up, @vazexqi , and thank you for reporting this, @JimBTek .

@vazexqi I'm getting an error when running the Authorize an Org command:

Unknown config name "sfdcLoginUrl"

@vazexqi Also, I've been unable get connected to my sandbox since doing so the first time (after I remove the sfdcLoginUrl preference).

I run sfdx force:auth:web:login -r https://test.salesforce.com and successfully login via the browser, then see the 'Successfully authorized' message in my terminal, but my sandbox username does not appear in the status bar, and the Refresh and Deploy options never appear in my menus.

Would you like me to submit a separate issue for this?

Happy to help troubleshoot in any way I can.

Thanks.

@evanmcd - Is the sfdcLoginUrl property at the top level of your sfdx-project.json file? For example:

{
  "packageDirectories": [
    {
      "path": "force-app",
      "default": true
    },
    {
      "path": "unpackaged"
    },
    {
      "path": "utils"
    }
  ],
  "namespace": "",
  "sfdcLoginUrl": "https://test.salesforce.com",
  "sourceApiVersion": "44.0"
}

Thanks guys!

Yeah is does seem if I do it from the command line (terminal) outside of VSCode, it works and it updates the JSON for me. Another possible glitch is that VSCode does not appear to show the username of the correct org if you switch the Default Alias outside of VSCode. It still displayed my Production Username, but from the command line I could confirm my sandbox was the current default/primary org I was connected to, and when I did a deploy it went to the right org, but kinda scary when I am trying to:

  • create a project / pull from Production
  • then push to a sandbox
  • do work
  • push/pull against sandbox
  • commit
  • eventually push to production

Thanks for the fast responses!

@ruthemmanuelle sorry for the delay. Yes, I do have it at the top level as you've shown and am still getting the error.

@evanmcd The error Unknown config name ... comes from using sfdx force:config:set. You can not use sfdcLoginUrl as a config variable. Instead, that needs to go in your sfdx-project.json file. If you want to set a config var, you can try sfdx force:config:set instanceUrl=https://test.salesforce.com. I think the auth commands will use the following order:

  1. --instanceurl flag on the commands
  2. sfdcLoginUrl in the sfdx-project.json file
  3. instanceUrl in force:config:set
  4. SFDX_INSTANCE_URL envvar

Ahh thanks @amphro. My mistake for having it in the wrong file. I can now auth with an org successfully. Thanks for your help.

Related to #623

The implementation should be as follows:

  1. SFDX: Authorize an Org
  2. The VS Code selection UI prompt for the Org type (Sandbox, Production, Custom)
  3. If sanbox or prod are selected the login command is run against the default url for those types
  4. If custom is selected a text box dialog is shown for the user to type in the domain

These changes dont update the sfdx-project.json file.

Production is the default. We talked about having a --sandbox on the auth commands so users don't need to type in the sandbox url. I think that could be a good option to help support this from the CLI side. Custom would obviously just use the --instanceurl flag.

Hi I am having issues authorizing sandbox org, the issue i run into is
Kill the process running on port 1717 or use a custom connected app and update OauthLocalPort in the sfdx-project.json file.
need some inputs troubleshooting this error

@reddy12swetha I had the same error yesterday. For me it was part of a new project build using SFDX: Create Project with Manifest. ( originally I hadn't updated my sfdx-project.json to point at test.salesforce.com).

When I got to the authorize org step, the browser login page was redirecting to an old URL for my sandbox. It had been refreshed since my last login, and the server instance had changed. I was able to resolve it by using the "Login with a different user name" link when I retried the authorize command.

I am also finding this error, where if I change the sdfx-project.json file to the test URL, it still goes to the login URL. If I then manually change to test in the browser, it redirects incorrectly and the org isn't authorized.

Needless to say, this workflow has a lot of room for improvement.

Scott

I have used vscode and sfdx a lot in recent months, and I have to say it is quite great for Scratch Orgs.

I love how it shows you in the footer of vscode what org you are set to, and i was about to write up steps I would love to see, but @ntotten hit the nail on the head with his comment and related #623

It would be great to:

  • Pull source from Prod and convert to sfdx
  • switch to scratch org to do some work
  • once happy switch to a QA sandbox and deploy there
  • eventually push back to prod

Keep up the good work guys

@JimBTek - You mean that isn't possible now? I'm brand new to SFDX. Would you be so kind and explain the process to get changes made locally with SFDX into production?

Scott

@smolinari it's possible now in SFDX for sure. But you can't easily do so within the VSCode UI completely, you have to jump back and forth with terminal, especially to switch orgs. And its hard to do both sandboxes and production because the URL is different and you may have to tweak a json file.

But i think Aliases help.

Ok. I'll just have to do some trials and errors. 馃憤

Scott

This will ship in our next release. :)

I found the Best solution which i have found it randomly : only you have to do is to make the path in environment variable of the bin folder of the vsCode eg: C:\Program Files\Microsoft VS Codebin
now after this ur vs code authorise an org will work properly .

Was this page helpful?
0 / 5 - 0 ratings