Add OAuth Client Credentials flow for command-line batch mode - #1666
Open
ponpoke wants to merge 1 commit into
Open
Add OAuth Client Credentials flow for command-line batch mode#1666ponpoke wants to merge 1 commit into
ponpoke wants to merge 1 commit into
Conversation
|
Thanks for the contribution! Before we can merge this, we need @ponpoke to sign the Salesforce Inc. Contributor License Agreement. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds OAuth 2.0 Client Credentials Flow support for Data Loader command-line batch mode using External Client App credentials.
Addresses #1658.
Motivation
Data Loader command-line batch mode currently supports username/password authentication or interactive OAuth authentication.
For unattended service-to-service batch jobs, interactive browser authentication is not suitable. This change adds an opt-in OAuth 2.0 Client Credentials Flow while preserving the existing authentication behavior by default.
Configuration
Enable the flow with:
This reuses the existing External Client App configuration and Data Loader encryption mechanisms.
When
sfdc.oauth.flowis not specified, the existing authentication behavior remains unchanged.Unsupported non-empty OAuth flow values are rejected with a configuration error.
Setup and usage
1. Create an External Client App
In Salesforce Setup:
apiOAuth scope.For example:
Manage user data via APIs (api)A callback URL may be required when configuring OAuth, although it is not used by the Client Credentials Flow itself.
2. Configure the Client Credentials policy
Open the External Client App and configure its policy:
Data Loader operations run with the permissions of the configured Run As user.
That user must therefore have the required object, field, and operation permissions for the Data Loader process.
3. Get the client credentials
From the External Client App settings, obtain:
The Consumer Key is used as the client ID.
The Consumer Secret should be encrypted using Data Loader's existing
encrypt.batutility before storing it inconfig.properties.4. Create an encryption key
From the Data Loader
bindirectory:This creates the encryption key used to protect the Consumer Secret.
The key file should be stored securely and must not be committed to source control.
5. Encrypt the Consumer Secret
Encrypt the Consumer Secret:
Copy the encrypted output into
config.properties.Only the Consumer Secret is encrypted. The Consumer Key is stored as-is.
6. Configure
config.propertiesExample:
Using
/in Windows paths is recommended in Java.propertiesfiles.Alternatively, backslashes must be escaped:
process.encryptionKeyFile=C:\\Users\\username\\dataloaderconfig\\dataloader.keyFor Client Credentials Flow,
sfdc.usernameandsfdc.passwordare not required.7. Run the existing batch process
Existing Data Loader command-line invocation remains unchanged:
For example, an extract process can be run with:
On successful authentication, the log contains:
followed by the normal Salesforce session establishment.
No interactive browser login or username/password authentication is required.
Implementation
sfdc.oauth.flow=client_credentialsas a read-only configuration option.sfdc.oauth.flowis not configured.Test results
Tested with Eclipse Temurin JDK 17.0.19 on Windows.
Client Credentials related tests:
AppConfigEdgeTest: 8/8 passedOAuthClientCredentialsFlowTest: 3/3 passedFull unit test suite (
mvn clean package, using UTF-8 and an English JVM locale):The remaining failure is the pre-existing Windows-specific
AppUtilTest.testExectest. It attempts to executeechodirectly, butechois a Windows shell built-in rather than a standalone executable.That test is unchanged by this pull request.
No failures were observed in tests related to this change.
Manual E2E validation
Validated against a Salesforce org using:
process.batcommandResult:
Backward compatibility
This feature is opt-in.
When:
sfdc.oauth.flow=client_credentialsis not configured, Data Loader continues to use the existing authentication behavior.
Existing username/password authentication and interactive OAuth behavior are unchanged.