mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 17:22:45 -05:00
Refresh token with SqlToolService session update (#21308)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user