From 1f6482490ca46a61039378faccede4f37d5f70e2 Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Fri, 9 Sep 2022 08:59:53 -0700 Subject: [PATCH] handle default auth type (#20572) * handle default auth type * comments --- .../platform/connection/common/connectionManagement.ts | 2 +- .../test/common/testConnectionManagementService.ts | 2 +- .../connection/browser/connectionManagementService.ts | 9 ++++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/sql/platform/connection/common/connectionManagement.ts b/src/sql/platform/connection/common/connectionManagement.ts index 9f27e5d65a..8dd2151bbb 100644 --- a/src/sql/platform/connection/common/connectionManagement.ts +++ b/src/sql/platform/connection/common/connectionManagement.ts @@ -221,7 +221,7 @@ export interface IConnectionManagementService { /** * Gets the default authentication type from the configuration service */ - getDefaultAuthenticationTypeId(): string; + getDefaultAuthenticationTypeId(providerName: string): string; /** * Cancels the connection diff --git a/src/sql/platform/connection/test/common/testConnectionManagementService.ts b/src/sql/platform/connection/test/common/testConnectionManagementService.ts index 7b7e7e0c3a..2fd274163b 100644 --- a/src/sql/platform/connection/test/common/testConnectionManagementService.ts +++ b/src/sql/platform/connection/test/common/testConnectionManagementService.ts @@ -306,7 +306,7 @@ export class TestConnectionManagementService implements IConnectionManagementSer return undefined!; } - getDefaultAuthenticationTypeId(): string { + getDefaultAuthenticationTypeId(providerName: string): string { return undefined!; } diff --git a/src/sql/workbench/services/connection/browser/connectionManagementService.ts b/src/sql/workbench/services/connection/browser/connectionManagementService.ts index 0ce3d8a639..71c1b4303b 100644 --- a/src/sql/workbench/services/connection/browser/connectionManagementService.ts +++ b/src/sql/workbench/services/connection/browser/connectionManagementService.ts @@ -312,7 +312,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti // If there is no authentication type set, set it using configuration if (!newConnection.authenticationType || newConnection.authenticationType === '') { - newConnection.authenticationType = this.getDefaultAuthenticationTypeId(); + newConnection.authenticationType = this.getDefaultAuthenticationTypeId(newConnection.providerName); } // If the password is required and still not loaded show the dialog @@ -797,8 +797,11 @@ export class ConnectionManagementService extends Disposable implements IConnecti return defaultProvider && this._providers.has(defaultProvider) ? defaultProvider : undefined; } - public getDefaultAuthenticationTypeId(): string { - let defaultAuthenticationType = WorkbenchUtils.getSqlConfigValue(this._configurationService, Constants.defaultAuthenticationType); + public getDefaultAuthenticationTypeId(providerName: string): string { + // only return the default authentication type if the provider supports the AuthType option. + // Other issues with the implementation is tracked here: https://github.com/microsoft/azuredatastudio/issues/20573 + const authOption = this._capabilitiesService.getCapabilities(providerName)?.connection.connectionOptions?.find(option => option.specialValueType === ConnectionOptionSpecialType.authType); + const defaultAuthenticationType = authOption ? WorkbenchUtils.getSqlConfigValue(this._configurationService, Constants.defaultAuthenticationType) : undefined; return defaultAuthenticationType; }