Skip to content
Merged
2 changes: 2 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### New Features and Improvements

* Add support for discovery URL for browser based authentication flow.

### Bug Fixes

### Documentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ CachedTokenSource performBrowserAuth(
.withRedirectUrl(config.getEffectiveOAuthRedirectUrl())
.withBrowserTimeout(config.getOAuthBrowserAuthTimeout())
.withScopes(new ArrayList<>(scopes))
.withOpenIDConnectEndpoints(config.getOidcEndpoints())
.build();
Consent consent = client.initiateConsent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static class Builder {
private HttpClient hc;
private String accountId;
private Optional<Duration> browserTimeout = Optional.empty();
private OpenIDConnectEndpoints openIDConnectEndpoints;

public Builder() {}

Expand All @@ -51,6 +52,11 @@ public Builder withHttpClient(HttpClient hc) {
return this;
}

public Builder withOpenIDConnectEndpoints(OpenIDConnectEndpoints openIDConnectEndpoints) {
this.openIDConnectEndpoints = openIDConnectEndpoints;
return this;
}

public Builder withHost(String host) {
this.host = host;
return this;
Expand Down Expand Up @@ -102,6 +108,7 @@ public Builder withBrowserTimeout(Duration browserTimeout) {
private final SecureRandom random = new SecureRandom();
private final boolean isAws;
private final boolean isAzure;
private final OpenIDConnectEndpoints openIDConnectEndpoints;
private final Optional<Duration> browserTimeout;

private OAuthClient(Builder b) throws IOException {
Expand All @@ -113,15 +120,15 @@ private OAuthClient(Builder b) throws IOException {

DatabricksConfig config =
new DatabricksConfig().setHost(b.host).setAccountId(b.accountId).resolve();
OpenIDConnectEndpoints oidc = config.getOidcEndpoints();
if (oidc == null) {
openIDConnectEndpoints = b.openIDConnectEndpoints;
if (openIDConnectEndpoints == null) {
throw new DatabricksException(b.host + " does not support OAuth");
}

this.isAws = config.isAws();
this.isAzure = config.isAzure();
this.tokenUrl = oidc.getTokenEndpoint();
this.authUrl = oidc.getAuthorizationEndpoint();
this.tokenUrl = openIDConnectEndpoints.getTokenEndpoint();
this.authUrl = openIDConnectEndpoints.getAuthorizationEndpoint();
this.browserTimeout = b.browserTimeout;
this.scopes = b.scopes;
}
Expand All @@ -138,6 +145,10 @@ public String getClientSecret() {
return clientSecret;
}

public OpenIDConnectEndpoints getOidcEndpoints() {
return openIDConnectEndpoints;
}

public String getRedirectUrl() {
return redirectUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void clientAndConsentTest() throws IOException {
.withClientId(config.getClientId())
.withClientSecret(config.getClientSecret())
.withHost(config.getHost())
.withOpenIDConnectEndpoints(config.getOidcEndpoints())
.withRedirectUrl(config.getEffectiveOAuthRedirectUrl())
.withScopes(config.getScopes())
.build();
Expand Down Expand Up @@ -94,6 +95,7 @@ void clientAndConsentTestWithCustomRedirectUrl() throws IOException {
.withClientId(config.getClientId())
.withClientSecret(config.getClientSecret())
.withHost(config.getHost())
.withOpenIDConnectEndpoints(config.getOidcEndpoints())
.withRedirectUrl(config.getEffectiveOAuthRedirectUrl())
.withScopes(config.getScopes())
.build();
Expand Down
Loading