Initial commit for dSTS Auth (#13802)

* Initial commit for dSTS Auth

* Removed getDstsToken from accountManagementService. Renamed azureAccount to token.

* Renamed dstsToken to _token in connectionWidget

* Code Review Feedback. Renamed token to authToken in onFetchDatabases.

* Removed dsts options from Kusto package.json
This commit is contained in:
Justin M
2021-02-01 10:48:16 -08:00
committed by GitHub
parent 1c0259f4c5
commit 8f5dc1526a
6 changed files with 63 additions and 23 deletions

View File

@@ -251,7 +251,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
* @param connectionProfile Connection Profile
*/
public async addSavedPassword(connectionProfile: interfaces.IConnectionProfile): Promise<interfaces.IConnectionProfile> {
await this.fillInOrClearAzureToken(connectionProfile);
await this.fillInOrClearToken(connectionProfile);
return this._connectionStore.addSavedPassword(connectionProfile).then(result => result.profile);
}
@@ -310,7 +310,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
}
// Fill in the Azure account token if needed and open the connection dialog if it fails
let tokenFillSuccess = await this.fillInOrClearAzureToken(newConnection);
let tokenFillSuccess = await this.fillInOrClearToken(newConnection);
// If the password is required and still not loaded show the dialog
if ((!foundPassword && this._connectionStore.isPasswordRequired(newConnection) && !newConnection.password) || !tokenFillSuccess) {
@@ -468,7 +468,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
if (callbacks.onConnectStart) {
callbacks.onConnectStart();
}
let tokenFillSuccess = await this.fillInOrClearAzureToken(connection);
let tokenFillSuccess = await this.fillInOrClearToken(connection);
if (!tokenFillSuccess) {
throw new Error(nls.localize('connection.noAzureAccount', "Failed to get Azure account token for connection"));
}
@@ -803,17 +803,38 @@ export class ConnectionManagementService extends Disposable implements IConnecti
}
/**
* Fills in the Azure account token if it's needed for this connection and doesn't already have one
* Fills in the account token if it's needed for this connection and doesn't already have one
* and clears it if it isn't.
* @param connection The connection to fill in or update
*/
private async fillInOrClearAzureToken(connection: interfaces.IConnectionProfile): Promise<boolean> {
if (connection.authenticationType !== Constants.azureMFA && connection.authenticationType !== Constants.azureMFAAndUser) {
private async fillInOrClearToken(connection: interfaces.IConnectionProfile): Promise<boolean> {
if (connection.authenticationType !== Constants.azureMFA
&& connection.authenticationType !== Constants.azureMFAAndUser
&& connection.authenticationType !== Constants.dstsAuth) {
connection.options['azureAccountToken'] = undefined;
return true;
}
let azureResource = this.getAzureResourceForConnection(connection);
const accounts = await this._accountManagementService.getAccounts();
if (connection.authenticationType === Constants.dstsAuth) {
let dstsAccounts = accounts.filter(a => a.key.providerId.startsWith('dstsAuth'));
if (dstsAccounts.length <= 0) {
connection.options['azureAccountToken'] = undefined;
return false;
}
dstsAccounts[0].key.providerArgs = {
serverName: connection.serverName,
databaseName: connection.databaseName
};
let tokenPromise = await this._accountManagementService.getAccountSecurityToken(dstsAccounts[0], undefined, undefined);
connection.options['azureAccountToken'] = tokenPromise.token;
return true;
}
const azureAccounts = accounts.filter(a => a.key.providerId.startsWith('azure'));
if (azureAccounts && azureAccounts.length > 0) {
let accountId = (connection.authenticationType === Constants.azureMFA || connection.authenticationType === Constants.azureMFAAndUser) ? connection.azureAccount : connection.userName;