Skip to content

SF CLI Authentication Methods

Salesforce CLI (SF CLI) provides multiple ways to manage authentication for your Salesforce orgs. Here are some common methods I frequently reference.

1. Authenticate via Web Interface

For interactive login, use the web method to authenticate through a browser.

sf org login web --alias <alias> --instance-url <instance-url>
  • --alias <alias>: Sets an alias for your org.
  • --instance-url <instance-url>: Specifies the Salesforce instance URL.

Example:

sf org login web --alias int --instance-url https://corpa--int.sandbox.my.salesforce.com

2. Display Org Information

To view details of a Salesforce org, such as username and instance URL, use the sf org display command.

sf org display --target-org <org-alias> --verbose --json
  • --target-org <org-alias>: Specifies the org alias.
  • --verbose: Provides detailed output.
  • --json: Outputs results in JSON format.

This is useful for quickly fetching a ClientId and RefreshToken used for CI/CD workflows.

3. Authenticate Using SFDX URL

You can authenticate via an SFDX URL, useful for automation scripts or CI/CD pipelines.

echo <sfdx-url> | sf org login sfdx-url --sfdx-url-stdin
  • echo <sfdx-url>: Provides the SFDX URL.
  • sf org login sfdx-url --sfdx-url-stdin: Logs in using the URL.