mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-01 17:23:35 -05:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user