Skip to content

[PLUGIN-1953] Support for client credentials Grant type#353

Open
vikasrathee-cs wants to merge 1 commit intodevelopfrom
client_creds
Open

[PLUGIN-1953] Support for client credentials Grant type#353
vikasrathee-cs wants to merge 1 commit intodevelopfrom
client_creds

Conversation

@vikasrathee-cs
Copy link
Copy Markdown
Contributor

@vikasrathee-cs vikasrathee-cs commented Mar 19, 2026

Support for client credentials Grant type

Jira : PLUGIN-1953

Summary

Adds support for the Client Credentials OAuth grant type to all Salesforce plugins (source, sink, streaming, connector).

Files updated

Widgets (UI)

Expose the OAuth Grant Type radio group and add a filter that hides username / password / securityToken when client_credentials is selected.

  • widgets/Salesforce-connector.json
  • widgets/Salesforce-batchsink.json
  • widgets/Salesforce-batchsource.json
  • widgets/Salesforce-streamingsource.json
  • widgets/SalesforceMultiObjects-batchsource.json

Docs

Document the new Grant Type field, clarify which fields are required per grant type, and note that client_credentials requires an instance-specific login URL.

  • docs/Salesforce-connector.md
  • docs/Salesforce-batchsink.md
  • docs/Salesforce-batchsource.md
  • docs/Salesforce-streamingsource.md
  • docs/SalesforceMultiObjects-batchsource.md

What's new

New config property authenticationGrantType backed by the pre-existing AuthenticatorCredentials.GrantType enum (password / client_credentials). Null is treated as password so upgraded pipelines that were saved before this change keep working without manual edits.

Validation

New validateAuthenticationFields(FailureCollector) on SalesforceConnectorBaseConfig:

  • Always required: consumerKey, consumerSecret, loginUrl.
  • Only required for password: username, password, securityToken.
  • Macro-aware skips any field whose value is a macro, and skips entirely if the grant type itself is a macro.
  • Each missing field reports its own failure tied to its withConfigProperty(...), so the UI highlights the exact field.

UI changes

  • New OAuth Grant Type radio group (inline layout, defaults to password) added to all five widget JSONs.
  • A GrantTypePassword filter hides username / password / securityToken when client_credentials is selected, so users only see the fields they need to fill in.

Screenshots

  • Radio [Password]
image
  • Radio [Client Credentials]
image
  • Missing value validation
image

Tests added

New file: SalesforceConnectorBaseConfigTest.java (250 lines) covering validateAuthenticationFields():

  • Password grant happy path + one test per missing field (consumerKey, consumerSecret, loginUrl, username, password, securityToken), including empty-string handling, plus an all-missing test that asserts exactly 6 failures on the right fields.
  • Client Credentials grant happy path, missing consumerKey / consumerSecret / loginUrl, explicit assertion that username / password / securityToken are not flagged, and an all-missing test that asserts exactly 3 failures.
  • Default behavior null authenticationGrantType falls back to PASSWORD validation rules.

Additional notes for reviewer

  • Backward compatibility: existing pipelines persisted without authenticationGrantType will deserialize with a null value, which getAuthenticationGrantType() maps to PASSWORD.

  • Login URL gotcha: client_credentials requires an instance-specific URL (e.g. https://<instance>.my.salesforce.com/services/oauth2/token) rather than the generic login.salesforce.com endpoint. This is called out in the updated docs.

Copy link
Copy Markdown
Contributor

@itsankit-google itsankit-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is okay to remove null check because it is not required in certain cases.

But we should also add validation for the type when these configs are required.

@vikasrathee-cs
Copy link
Copy Markdown
Contributor Author

it is okay to remove null check because it is not required in certain cases.

But we should also add validation for the type when these configs are required.

As of now, there is no explicit variable defined which calculates whether user is supporting password grant or client_creds. Based on the values, if user name and password are null, it will fallback to client creds automatically. This was done to support DTS use case I guess.

@itsankit-google
Copy link
Copy Markdown
Contributor

it is okay to remove null check because it is not required in certain cases.
But we should also add validation for the type when these configs are required.

As of now, there is no explicit variable defined which calculates whether user is supporting password grant or client_creds. Based on the values, if user name and password are null, it will fallback to client creds automatically. This was done to support DTS use case I guess.

As discussed offline, this way we will not be able to maintain the extensibility of CDF plugin's ability to support multiple auth types.

We can add a AuthenticationType similar to google-cloud plugins to correctly fix this.

We can also hide certain fields in CDF Plugin UI based on authenticationType.

@vikasrathee-cs vikasrathee-cs changed the title Removed null check for username password for client credentials type. [PLUGIN-1953] Support for client credentials Grant type Mar 31, 2026
getConsumerSecret()))
.put(SalesforceConstants.CONFIG_LOGIN_URL, Objects.requireNonNull(config.getConnection().getLoginUrl()));
switch (config.getConnection().getAuthenticationGrantType()) {
case BASIC_AUTHENTICATION:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no basic auth in salesforce, previously password grant type was supported and now it is client creds also


public AuthenticationGrantType getAuthenticationGrantType() {
if (!Strings.isNullOrEmpty(authenticationGrantType) &&
authenticationGrantType.equals(AuthenticationGrantType.BASIC_AUTHENTICATION.getValue())) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it password grant type as default

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is handeled by the else case

// Default auth, handles null case when upgrading pipeline
    return SalesforceConstants.DEFAULT_GRANT_TYPE

{
"name": "GrantTypeBasicAuthentication",
"condition": {
"expression": "authenticationGrantType == 'basicAuthentication'"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it not clientCredentialsAuthentication, then it will be backward compatible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated!

Copy link
Copy Markdown
Contributor Author

@vikasrathee-cs vikasrathee-cs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the auth type from based to password grant type

* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AuthenticatorCredentials class already has a GrantType available which is getting used in DTS also, it should be set based on this UI property.

That existing class can be used instead of this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this class

.put(SalesforceConstants.CONFIG_CONSUMER_SECRET,
Objects.requireNonNull(config.getConnection().getConsumerSecret()))
.put(SalesforceConstants.CONFIG_LOGIN_URL, Objects.requireNonNull(config.getConnection().getLoginUrl()));
if (config.getConnection().getAuthenticationGrantType() == AuthenticatorCredentials.GrantType.PASSWORD) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if grant type is password then only this configuration is mandatory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants