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.
- Open a terminal (macOS and Linux) or command prompt (Windows).
-
Run the org display command to get the instance
URL for the org to connect to. See the value for the Instance
Url key.
1sf org display --target-org myorg 2=== Org Description 3 4 KEY VALUE 5 ─────────────── ─────────────────────────────────────────────── 6 Access Token [REDACTED] Use 'sf org auth show-access-token' to view 7... 8 Instance Url https://creative-impala-20hx3-dev-ed.my.salesforce.com 9... -
Run the org auth show-access-token command to get
the access token.
1sf org auth show-access-token --target-org myorg 2 3✔ You're about to reveal the access token for "myorg". This token grants full access 4to the org with your current permissions. Sharing or logging this token is equivalent to sharing your 5credentials. Do you want to continue? 6 7# Yes 8┌──────────────┬────────────────────────────────────────────┐ 9│ Key │ Value │ 10├──────────────┼────────────────────────────────────────────┤ 11│ Access Token │ 00D8H0000007wprAQkAQAlOT5H<truncated> │ 12└──────────────┴────────────────────────────────────────────┘ -
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 -
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. For
example:
1sf project deploy start --source-dir <source-dir> --target-org 00D8H0000007wprAQkAQAlOT5H
Salesforce CLI doesn’t store the access token in its internal files. It uses it only for this CLI command run.