Skip to content

Make client ID optional in DatabricksOAuthTokenSource#820

Merged
hectorcast-db merged 1 commit into
mainfrom
fix-oauth-tokensource-optional-clientid
Jun 4, 2026
Merged

Make client ID optional in DatabricksOAuthTokenSource#820
hectorcast-db merged 1 commit into
mainfrom
fix-oauth-tokensource-optional-clientid

Conversation

@hectorcast-db
Copy link
Copy Markdown
Contributor

Summary

Makes the OAuth client ID optional in DatabricksOAuthTokenSource so that users authenticated through a web browser OAuth flow can perform token exchange (account-wide token federation).

Why

DatabricksOAuthTokenSource.getToken() required a non-null, non-empty clientId (Objects.requireNonNull(clientId, "ClientID cannot be null") plus an isEmpty() check) and unconditionally sent it as the client_id form parameter. This assumes a service-principal (Workload Identity Federation) flow.

Users authenticated through a web browser OAuth flow do not have a client ID in their IdP JWT, so they hit:

java.lang.NullPointerException: ClientID cannot be null
	at com.databricks.sdk.core.oauth.DatabricksOAuthTokenSource.getToken(DatabricksOAuthTokenSource.java:148)

This made the OAuth federation token exchange flow unusable for these users, who had to set a dummy service-principal client ID as a workaround.

The Go SDK already treats an empty client ID as account-wide token federation and simply omits the parameter. This PR brings the Java SDK in line.

Fixes #757.

What changed

Interface changes

None. The DatabricksOAuthTokenSource.Builder(clientId, ...) constructor signature is unchanged; clientId may now be null or empty.

Behavioral changes

  • When clientId is null or empty, getToken() no longer throws — it omits the client_id parameter from the token exchange request, performing account-wide token federation.
  • A non-null/non-empty clientId continues to be sent exactly as before.

Internal changes

  • Removed the requireNonNull/isEmpty validation for clientId and made the client_id form parameter conditional on a non-empty value.
  • Updated the Builder and getToken() Javadoc to document that the client ID is optional.

How is this tested?

Updated DatabricksOAuthTokenSourceTest: the "Null client ID" and "Empty client ID" cases now assert a successful token exchange against a request that omits client_id, instead of expecting an exception. mvn test -Dtest=DatabricksOAuthTokenSourceTest passes (14 tests, 0 failures).

getToken() previously required a non-null, non-empty client ID and always
sent it as the client_id form parameter, throwing NullPointerException
("ClientID cannot be null") otherwise. This broke token exchange for users
authenticated through a web browser OAuth flow, whose IdP JWT does not
contain a client ID.

When the client ID is null or empty, the client_id parameter is now omitted
from the token exchange request to perform account-wide token federation,
matching the Go SDK behavior.

Fixes #757

Signed-off-by: Hector Castejon Diaz <hector.castejon@databricks.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-java

Inputs:

  • PR number: 820
  • Commit SHA: e73b47dd088a9a3097f635f59f63868bb1e74d24

Checks will be approved automatically on success.

@hectorcast-db hectorcast-db added this pull request to the merge queue Jun 4, 2026
Merged via the queue into main with commit 2b44706 Jun 4, 2026
17 checks passed
@hectorcast-db hectorcast-db deleted the fix-oauth-tokensource-optional-clientid branch June 4, 2026 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ISSUE] DatabricksOAuthTokenSource relies on mandatory client id - not suitable for Web oauth2 use cases

2 participants