in src/controllers/connectionManager.ts [846:891]
public async refreshAzureAccountToken(uri: string): Promise<void> {
const profile = this.getConnectionInfo(uri);
if (!profile) {
this.vscodeWrapper.logToOutputChannel(Utils.formatString(LocalizedConstants.msgConnectionNotFound, uri));
return;
}
// Wait for the pending reconnction promise if any
const previousReconnectPromise = this._uriToConnectionPromiseMap.get(uri);
if (previousReconnectPromise) {
this.vscodeWrapper.logToOutputChannel(Utils.formatString(LocalizedConstants.msgFoundPendingReconnect, uri));
try {
const previousConnectionResult = await previousReconnectPromise;
if (previousConnectionResult) {
this.vscodeWrapper.logToOutputChannel(Utils.formatString(LocalizedConstants.msgPendingReconnectSuccess, uri));
return;
}
this.vscodeWrapper.logToOutputChannel(Utils.formatString(LocalizedConstants.msgFoundPendingReconnectFailed, uri));
} catch (err) {
this.vscodeWrapper.logToOutputChannel(Utils.formatString(LocalizedConstants.msgFoundPendingReconnectError, uri, err));
}
}
const expiry = profile.credentials.expiresOn;
if (typeof expiry === 'number' && !Number.isNaN(expiry)) {
const currentTime = new Date().getTime() / 1000;
const maxTolerance = 2 * 60; // two minutes
if (expiry - currentTime < maxTolerance) {
this.vscodeWrapper.logToOutputChannel(Utils.formatString(LocalizedConstants.msgAcessTokenExpired, profile.connectionId, uri));
try {
let connectionResult = await this.connect(uri, profile.credentials);
if (!connectionResult) {
this.vscodeWrapper.showErrorMessage(Utils.formatString(LocalizedConstants.msgRefreshConnection, profile.connectionId, uri));
throw new Error('Unable to refresh connection');
}
this.vscodeWrapper.logToOutputChannel(Utils.formatString(LocalizedConstants.msgRefreshTokenSuccess,
profile.connectionId, uri, this.getConnectionInfo(uri)));
return;
} catch {
this.vscodeWrapper.showInformationMessage(Utils.formatString(LocalizedConstants.msgRefreshTokenError));
}
}
this.vscodeWrapper.logToOutputChannel(Utils.formatString(LocalizedConstants.msgRefreshTokenNotNeeded, profile.connectionId, uri));
}
return;
}