Skip to content

Commit b50289c

Browse files
authored
Pass Account Id to OAuthClient in External Browser Authentication. (#479)
## What changes are proposed in this pull request? Users with membership in multiple Databricks accounts are sent to an incorrect authorization URL with the external-browser auth type in the Java SDK. Because the new DatabricksConfig created in the OAuthClient doesn't include the account ID so getOidcEndpoints returns endpoints with no account ID in the path. Which redirects it to the default account and not the account that was specified in the intial Config. ## How is this tested? Manually tested that it is not the case anymore using the below code. ``` public static void main(String[] args) { DatabricksConfig config = new DatabricksConfig() .setAuthType("external-browser") .setHost("https://accounts.cloud.databricks.com") .setAccountId("<redacted>") .setScopes(List.of("all-apis", "offline_access")) .setOAuthRedirectUrl("http://localhost:8022"); AccountClient acct = new AccountClient(config); for (Workspace w: acct.workspaces().list()){ System.out.println(w.getWorkspaceName()); } } ``` The current code is not flexible enough to have unit tests in it and needs a bigger refactor. So, unit tests are not added. NO_CHANGELOG=true
1 parent f0582e8 commit b50289c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/ExternalBrowserCredentialsProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ CachedTokenSource performBrowserAuth(
112112
.withClientId(clientId)
113113
.withClientSecret(clientSecret)
114114
.withHost(config.getHost())
115+
.withAccountId(config.getAccountId())
115116
.withRedirectUrl(config.getEffectiveOAuthRedirectUrl())
116117
.withScopes(config.getScopes())
117118
.build();

databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/OAuthClient.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static class Builder {
3535
private List<String> scopes;
3636
private String clientSecret;
3737
private HttpClient hc;
38+
private String accountId;
3839

3940
public Builder() {}
4041

@@ -71,6 +72,11 @@ public Builder withScopes(List<String> scopes) {
7172
public OAuthClient build() throws IOException {
7273
return new OAuthClient(this);
7374
}
75+
76+
public Builder withAccountId(String accountId) {
77+
this.accountId = accountId;
78+
return this;
79+
}
7480
}
7581

7682
private final String clientId;
@@ -92,7 +98,8 @@ private OAuthClient(Builder b) throws IOException {
9298
this.host = b.host;
9399
this.hc = b.hc;
94100

95-
DatabricksConfig config = new DatabricksConfig().setHost(b.host).resolve();
101+
DatabricksConfig config =
102+
new DatabricksConfig().setHost(b.host).setAccountId(b.accountId).resolve();
96103
OpenIDConnectEndpoints oidc = config.getOidcEndpoints();
97104
if (oidc == null) {
98105
throw new DatabricksException(b.host + " does not support OAuth");

0 commit comments

Comments
 (0)