@@ -13,6 +13,7 @@ export interface OAuthManagerOptions {
1313 clientId ?: string ;
1414 azureTenantId ?: string ;
1515 clientSecret ?: string ;
16+ useDatabricksOAuthInAzure ?: boolean ;
1617 context : IClientContext ;
1718}
1819
@@ -189,24 +190,35 @@ export default abstract class OAuthManager {
189190 // normalize
190191 const host = options . host . toLowerCase ( ) . replace ( 'https://' , '' ) . split ( '/' ) [ 0 ] ;
191192
192- // eslint-disable-next-line @typescript-eslint/no-use-before-define
193- const managers = [ AWSOAuthManager , AzureOAuthManager ] ;
193+ const awsDomains = [ '.cloud.databricks.com' , '.dev.databricks.com' ] ;
194+ const isAWSDomain = awsDomains . some ( ( domain ) => host . endsWith ( domain ) ) ;
195+ if ( isAWSDomain ) {
196+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
197+ return new DatabricksOAuthManager ( options ) ;
198+ }
194199
195- for ( const OAuthManagerClass of managers ) {
196- for ( const domain of OAuthManagerClass . domains ) {
197- if ( host . endsWith ( domain ) ) {
198- return new OAuthManagerClass ( options ) ;
199- }
200+ if ( options . useDatabricksOAuthInAzure ) {
201+ const domains = [ '.azuredatabricks.net' ] ;
202+ const isSupportedDomain = domains . some ( ( domain ) => host . endsWith ( domain ) ) ;
203+ if ( isSupportedDomain ) {
204+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
205+ return new DatabricksOAuthManager ( options ) ;
200206 }
201207 }
202208
209+ const azureDomains = [ '.azuredatabricks.net' , '.databricks.azure.us' , '.databricks.azure.cn' ] ;
210+ const isAzureDomain = azureDomains . some ( ( domain ) => host . endsWith ( domain ) ) ;
211+ if ( isAzureDomain ) {
212+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
213+ return new AzureOAuthManager ( options ) ;
214+ }
215+
203216 throw new Error ( `OAuth is not supported for ${ options . host } ` ) ;
204217 }
205218}
206219
207- export class AWSOAuthManager extends OAuthManager {
208- public static domains = [ '.cloud.databricks.com' , '.dev.databricks.com' ] ;
209-
220+ // Databricks InHouse OAuth Manager
221+ export class DatabricksOAuthManager extends OAuthManager {
210222 public static defaultClientId = 'databricks-sql-connector' ;
211223
212224 public static defaultCallbackPorts = [ 8030 ] ;
@@ -220,17 +232,15 @@ export class AWSOAuthManager extends OAuthManager {
220232 }
221233
222234 protected getClientId ( ) : string {
223- return this . options . clientId ?? AWSOAuthManager . defaultClientId ;
235+ return this . options . clientId ?? DatabricksOAuthManager . defaultClientId ;
224236 }
225237
226238 protected getCallbackPorts ( ) : Array < number > {
227- return this . options . callbackPorts ?? AWSOAuthManager . defaultCallbackPorts ;
239+ return this . options . callbackPorts ?? DatabricksOAuthManager . defaultCallbackPorts ;
228240 }
229241}
230242
231243export class AzureOAuthManager extends OAuthManager {
232- public static domains = [ '.azuredatabricks.net' , '.databricks.azure.cn' , '.databricks.azure.us' ] ;
233-
234244 public static defaultClientId = '96eecda7-19ea-49cc-abb5-240097d554f5' ;
235245
236246 public static defaultCallbackPorts = [ 8030 ] ;
0 commit comments