Skip to content

Commit 7ff54e5

Browse files
hectorcast-dbclaude
andcommitted
Refactor: Extract OIDC endpoint fetching to reusable method
Extract the logic for fetching OIDC endpoints from the well-known endpoint into a helper method fetchOidcEndpointsFromWellKnown(). This method is now reused for both the Azure client secret authentication case and the default case, reducing code duplication. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 132f54c commit 7ff54e5

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

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

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,21 @@ private OpenIDConnectEndpoints getUnifiedOidcEndpoints(String accountId) throws
787787
return new OpenIDConnectEndpoints(prefix + "/v1/token", prefix + "/v1/authorize");
788788
}
789789

790+
private OpenIDConnectEndpoints fetchOidcEndpointsFromWellKnown() throws IOException {
791+
ApiClient apiClient =
792+
new ApiClient.Builder()
793+
.withHttpClient(getHttpClient())
794+
.withGetHostFunc(v -> getHost())
795+
.build();
796+
try {
797+
return apiClient.execute(
798+
new Request("GET", "/oidc/.well-known/oauth-authorization-server"),
799+
OpenIDConnectEndpoints.class);
800+
} catch (IOException e) {
801+
throw new DatabricksException("IO error: " + e.getMessage(), e);
802+
}
803+
}
804+
790805
private OpenIDConnectEndpoints fetchDefaultOidcEndpoints() throws IOException {
791806
if (getHost() == null) {
792807
return null;
@@ -798,33 +813,14 @@ private OpenIDConnectEndpoints fetchDefaultOidcEndpoints() throws IOException {
798813
}
799814

800815
if (isAzure() && getAzureClientId() != null) {
801-
Request request = new Request("GET", getHost() + "/oidc/oauth2/v2.0/authorize");
802-
request.setRedirectionBehavior(false);
803-
Response resp = getHttpClient().execute(request);
804-
String realAuthUrl = resp.getFirstHeader("location");
805-
if (realAuthUrl == null) {
806-
return null;
807-
}
808-
return new OpenIDConnectEndpoints(
809-
realAuthUrl.replaceAll("/authorize", "/token"), realAuthUrl);
816+
return fetchOidcEndpointsFromWellKnown();
810817
}
811818
if (isAccountClient() && getAccountId() != null) {
812819
String prefix = getHost() + "/oidc/accounts/" + getAccountId();
813820
return new OpenIDConnectEndpoints(prefix + "/v1/token", prefix + "/v1/authorize");
814821
}
815822

816-
ApiClient apiClient =
817-
new ApiClient.Builder()
818-
.withHttpClient(getHttpClient())
819-
.withGetHostFunc(v -> getHost())
820-
.build();
821-
try {
822-
return apiClient.execute(
823-
new Request("GET", "/oidc/.well-known/oauth-authorization-server"),
824-
OpenIDConnectEndpoints.class);
825-
} catch (IOException e) {
826-
throw new DatabricksException("IO error: " + e.getMessage(), e);
827-
}
823+
return fetchOidcEndpointsFromWellKnown();
828824
}
829825

830826
@Override

0 commit comments

Comments
 (0)