Refresh token with SqlToolService session update (#21308)

This commit is contained in:
Cheena Malhotra
2022-11-29 15:26:15 -08:00
committed by GitHub
parent 0479aab107
commit 23dfd690a6
7 changed files with 41 additions and 14 deletions

View File

@@ -48,7 +48,6 @@ export class RefreshAction extends Action {
if (this.element instanceof ConnectionProfile) {
let connection: ConnectionProfile = this.element;
if (this._connectionManagementService.isConnected(undefined, connection)) {
await this._connectionManagementService.refreshAzureAccountTokenIfNecessary(connection);
treeNode = this._objectExplorerService.getObjectExplorerNode(connection);
if (treeNode === undefined) {
await this._objectExplorerService.updateObjectExplorerNodes(connection.toIConnectionProfile());
@@ -56,8 +55,6 @@ export class RefreshAction extends Action {
}
}
} else if (this.element instanceof TreeNode) {
let connection: ConnectionProfile = this.element.getConnectionProfile();
this._connectionManagementService.refreshAzureAccountTokenIfNecessary(connection);
treeNode = this.element;
}

View File

@@ -440,7 +440,8 @@ export class ObjectExplorerService implements IObjectExplorerService {
allProviders.forEach(provider => {
self.callExpandOrRefreshFromProvider(provider, {
sessionId: session.sessionId!,
nodePath: node.nodePath
nodePath: node.nodePath,
token: session.token
}, refresh).then(isExpanding => {
if (!isExpanding) {
// The provider stated it's not going to expand the node, therefore do not need to track when merging results
@@ -595,7 +596,18 @@ export class ObjectExplorerService implements IObjectExplorerService {
session: azdata.ObjectExplorerSession,
parentTree: TreeNode,
refresh: boolean = false): Promise<TreeNode[]> {
const providerName = parentTree.getConnectionProfile()?.providerName;
let connection = parentTree.getConnectionProfile();
if (connection) {
// Refresh access token on connection if needed.
let refreshResult = await this._connectionManagementService.refreshAzureAccountTokenIfNecessary(connection);
if (refreshResult) {
session.token = {
token: connection.options['azureAccountToken'],
expiresOn: connection.options['expiresOn']
};
}
}
const providerName = connection?.providerName;
if (!providerName) {
throw new Error('Failed to expand node - no provider name');
}

View File

@@ -262,6 +262,7 @@ suite('SQL Object Explorer Service tests', () => {
connectionManagementService = TypeMoq.Mock.ofType(TestConnectionManagementService, TypeMoq.MockBehavior.Strict);
connectionManagementService.setup(x => x.getConnectionGroups()).returns(() => [conProfGroup]);
connectionManagementService.setup(x => x.getActiveConnections()).returns(() => [connection]);
connectionManagementService.setup(x => x.refreshAzureAccountTokenIfNecessary(TypeMoq.It.isAny())).returns(async () => true);
connectionManagementService.setup(x => x.addSavedPassword(TypeMoq.It.isAny())).returns(() => new Promise<ConnectionProfile>((resolve) => {
resolve(connection);
}));