Newer Version Available
Use an Existing Access Token instead of Authorizing
When you authorize into an org using the auth
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
--targetusername | -u parameter accept an access token. The only
exception is
force:user:display.
- To get the instance URL and access token for the org to connect to, run the force:org:display command. See Authorization Information for an Org.
-
Use config:set to set the instanceUrl config value.
1sfdx config:set instanceUrl=https://na35.salesforce.com -
When you run the CLI command, use the org’s access token as the value for the --targetusername parameter rather than the org’s username.
1sfdx force:source:deploy --sourcepath <source-dir> --targetusername <access-token>
The CLI doesn’t store the access token in its internal files. It uses it only for this CLI command run.