Skip to content

Commit 822d47e

Browse files
committed
Honor discovery url for flows other than M2M
1 parent 72de0ee commit 822d47e

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

databricks-sdk-java/src/main/java/com/databricks/sdk/core/DatabricksConfig.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@
1717
import java.time.Duration;
1818
import java.util.*;
1919
import org.apache.http.HttpMessage;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
2022

2123
public class DatabricksConfig {
24+
private static final Logger LOG = LoggerFactory.getLogger(DatabricksConfig.class);
2225
private CredentialsProvider credentialsProvider = new DefaultCredentialsProvider();
2326

2427
@ConfigAttribute(env = "DATABRICKS_HOST")
@@ -647,7 +650,19 @@ public OpenIDConnectEndpoints getOidcEndpoints() throws IOException {
647650
if (discoveryUrl == null) {
648651
return fetchDefaultOidcEndpoints();
649652
}
650-
return fetchOidcEndpointsFromDiscovery();
653+
try {
654+
OpenIDConnectEndpoints oidcEndpoints = fetchOidcEndpointsFromDiscovery();
655+
if (oidcEndpoints != null) {
656+
return oidcEndpoints;
657+
}
658+
} catch (Exception e) {
659+
LOG.warn(
660+
"Failed to fetch OIDC Endpoints using discovery URL: {}. Error: {}. \nDefaulting to fetch OIDC using default endpoint.",
661+
discoveryUrl,
662+
e.getMessage(),
663+
e);
664+
}
665+
return fetchDefaultOidcEndpoints();
651666
}
652667

653668
private OpenIDConnectEndpoints fetchOidcEndpointsFromDiscovery() {
@@ -737,6 +752,7 @@ public DatabricksEnvironment getDatabricksEnvironment() {
737752
}
738753

739754
private DatabricksConfig clone(Set<String> fieldsToSkip) {
755+
fieldsToSkip.add("LOG");
740756
DatabricksConfig newConfig = new DatabricksConfig();
741757
for (Field f : DatabricksConfig.class.getDeclaredFields()) {
742758
if (fieldsToSkip.contains(f.getName())) {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public static class Builder {
4343
private HttpClient hc;
4444
private String accountId;
4545
private Optional<Duration> browserTimeout = Optional.empty();
46+
private String discoveryUrl;
4647

4748
public Builder() {}
4849

@@ -89,6 +90,11 @@ public Builder withBrowserTimeout(Duration browserTimeout) {
8990
this.browserTimeout = Optional.of(browserTimeout);
9091
return this;
9192
}
93+
94+
public Builder withDiscoveryUrl(String discoveryUrl) {
95+
this.discoveryUrl = discoveryUrl;
96+
return this;
97+
}
9298
}
9399

94100
private final String clientId;
@@ -112,7 +118,7 @@ private OAuthClient(Builder b) throws IOException {
112118
this.hc = b.hc;
113119

114120
DatabricksConfig config =
115-
new DatabricksConfig().setHost(b.host).setAccountId(b.accountId).resolve();
121+
new DatabricksConfig().setHost(b.host).setAccountId(b.accountId).setDiscoveryUrl(b.discoveryUrl).resolve();
116122
OpenIDConnectEndpoints oidc = config.getOidcEndpoints();
117123
if (oidc == null) {
118124
throw new DatabricksException(b.host + " does not support OAuth");

0 commit comments

Comments
 (0)