Newer Version Available

This content describes an older version of this product. View Latest

Use an Existing Access Token

When you authorize an org using the org login commands, Salesforce CLI takes care of generating and refreshing all tokens, such as the access token. But sometimes you want to run a few CLI commands against an existing org without going through the entire authorization process. In this case, you provide the access token and URL of the Salesforce instance that hosts the org to which you want to connect.
Almost all CLI commands that have the --target-org | -o flag accept an access token. The only exception is org display user.
  1. Open a terminal (macOS and Linux) or command prompt (Windows).
  2. To get the instance URL and access token for the org to connect to, run the org display command. See the values for the Access Token and Instance Url keys.
    1sf org display --target-org myorg
    2=== Org Description
    3
    4 KEY             VALUE                                           
    5 ─────────────── ───────────────────────────────────────────────
    6 Access Token    00D8H0000007wpr!AQkAQAlOT5H (truncated for security) 
    7...
    8 Instance Url    https://creative-impala-20hx3-dev-ed.my.salesforce.com  
    9...
  3. Use config set to set the org-instance-url configuration variable. To set it locally, run the command from a Salesforce DX project; to set it globally, use the --global flag.
    1sf config set org-instance-url=https://creative-impala-20hx3-dev-ed.my.salesforce.com --global
  4. When you run the CLI command, use the org’s access token as the value for the --target-org flag rather than the org’s username.
    1sf project deploy start --source-dir <source-dir> --target-org 00D8H0000007wpr!AQkAQAlOT5H

Salesforce CLI doesn’t store the access token in its internal files. It uses it only for this CLI command run.