Authorize an Org Using a Browser
Authorize an org with a browser by running a CLI command and entering your credentials
in the browser that automatically opens. That’s it!
Use this authorization method when multi-factor authentication (MFA) is enabled on your
org, either directly with a username and password or via single sign-on (SSO).
- Open a terminal (macOS and Linux) or command prompt (Windows).
-
Run the org login web CLI command. We recommend
using the --alias flag to make it easy to refer to
the org later.
sf org login web --alias my-org
Use the --set-default flag if you want the org to be the default for commands that accept the --target-org flag. If you’re authorizing a Dev Hub org, use the --set-default-dev-hub flag instead. See the org login web command for examples. - In the browser window that opens, sign in to your org with your Salesforce login credentials. Click Allow, which allows Salesforce CLI to access to your org.
- Close the browser window. Your org is now authorized!
If the URL that you use to log in to your org isn’t the default (login.salesforce.com), update your project configuration file
(sfdx-project.json). Set the sfdcLoginUrl option to your My Domain login URL. For
example:
"sfdcLoginUrl" : "https://MyDomainName.my.salesforce.com"
This example is for a sandbox.
"sfdcLoginUrl" : "https://MyDomainName--SandboxName.sandbox.my.salesforce.com"
Alternatively, you can use the --instance-url flag of org login web to specify the URL. This value overrides the login URL you specified in the sfdx-project.json file. For example:
sf org login web --alias my-hub-org --instance-url https://exciting.sandbox.my.salesforce.com
Also, the orgs you authorize for Salesforce CLI are required to have a connected app. We provide a default connected app called Salesforce CLI. If you need more security or control, such as setting the refresh token timeout or specifying IP ranges, create your own connected app. You can also configure the default connected app to be more secure.