Skip to content

Commit eed5737

Browse files
committed
Fallback for discovery URL
1 parent 4db2b8b commit eed5737

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
import java.lang.reflect.Field;
1414
import java.util.*;
1515
import org.apache.http.HttpMessage;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
1618

1719
public class DatabricksConfig {
20+
private static final Logger LOG = LoggerFactory.getLogger(DefaultCredentialsProvider.class);
1821
private CredentialsProvider credentialsProvider = new DefaultCredentialsProvider();
1922

2023
@ConfigAttribute(env = "DATABRICKS_HOST")
@@ -545,7 +548,19 @@ public OpenIDConnectEndpoints getOidcEndpoints() throws IOException {
545548
if (discoveryUrl == null) {
546549
return fetchDefaultOidcEndpoints();
547550
}
548-
return fetchOidcEndpointsFromDiscovery();
551+
try {
552+
OpenIDConnectEndpoints oidcEndpoints = fetchOidcEndpointsFromDiscovery();
553+
if (oidcEndpoints != null) {
554+
return oidcEndpoints;
555+
}
556+
} catch (Exception e) {
557+
LOG.debug(
558+
"Failed to fetch OIDC Endpoints using discovery URL: {}. Error: {}. \nDefaulting to fetch OIDC using default endpoint.",
559+
discoveryUrl,
560+
e.getMessage(),
561+
e);
562+
}
563+
return fetchDefaultOidcEndpoints();
549564
}
550565

551566
private OpenIDConnectEndpoints fetchOidcEndpointsFromDiscovery() {

databricks-sdk-java/src/test/java/com/databricks/sdk/core/DatabricksConfigTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,35 @@ public void testDiscoveryEndpoint() throws IOException {
159159
}
160160
}
161161

162+
@Test
163+
public void testDiscoveryEndpointFetchThrowsError() throws IOException {
164+
String discoveryUrlSuffix = "/test.discovery.url";
165+
String OIDCResponse =
166+
"{\n"
167+
+ " \"authorization_endpoint\": \"https://test.auth.endpoint/oidc/v1/authorize\",\n"
168+
+ " \"token_endpoint\": \"https://test.auth.endpoint/oidc/v1/token\"\n"
169+
+ "}";
170+
171+
try (FixtureServer server =
172+
new FixtureServer()
173+
.with("GET", discoveryUrlSuffix, "", 400)
174+
.with("GET", "/oidc/.well-known/oauth-authorization-server", OIDCResponse, 200)) {
175+
176+
String discoveryUrl = server.getUrl() + discoveryUrlSuffix;
177+
178+
OpenIDConnectEndpoints oidcEndpoints =
179+
new DatabricksConfig()
180+
.setHost(server.getUrl())
181+
.setDiscoveryUrl(discoveryUrl)
182+
.setHttpClient(new CommonsHttpClient.Builder().withTimeoutSeconds(30).build())
183+
.getOidcEndpoints();
184+
185+
assertEquals(
186+
oidcEndpoints.getAuthorizationEndpoint(), "https://test.auth.endpoint/oidc/v1/authorize");
187+
assertEquals(oidcEndpoints.getTokenEndpoint(), "https://test.auth.endpoint/oidc/v1/token");
188+
}
189+
}
190+
162191
@Test
163192
public void testNewWithWorkspaceHost() {
164193
DatabricksConfig config =

0 commit comments

Comments
 (0)