Archived
1
0

chore(vscode): update to 1.54.2

This commit is contained in:
Joe Previte
2021-03-11 10:27:10 -07:00
1459 changed files with 53404 additions and 51004 deletions

View File

@ -144,7 +144,7 @@ export class AzureActiveDirectoryService {
this.pollForReconnect(session.id, session.refreshToken, session.scope);
}
} else {
await this.logout(session.id);
await this.removeSession(session.id);
}
}
});
@ -177,8 +177,8 @@ export class AzureActiveDirectoryService {
}
private async checkForUpdates(): Promise<void> {
const addedIds: string[] = [];
let removedIds: string[] = [];
const added: vscode.AuthenticationSession[] = [];
let removed: vscode.AuthenticationSession[] = [];
const storedData = await this._keychain.getToken();
if (storedData) {
try {
@ -187,13 +187,13 @@ export class AzureActiveDirectoryService {
const matchesExisting = this._tokens.some(token => token.scope === session.scope && token.sessionId === session.id);
if (!matchesExisting && session.refreshToken) {
try {
await this.refreshToken(session.refreshToken, session.scope, session.id);
addedIds.push(session.id);
const token = await this.refreshToken(session.refreshToken, session.scope, session.id);
added.push(this.convertToSessionSync(token));
} catch (e) {
if (e.message === REFRESH_NETWORK_FAILURE) {
// Ignore, will automatically retry on next poll.
} else {
await this.logout(session.id);
await this.removeSession(session.id);
}
}
}
@ -202,8 +202,8 @@ export class AzureActiveDirectoryService {
promises = promises.concat(this._tokens.map(async token => {
const matchesExisting = sessions.some(session => token.scope === session.scope && token.sessionId === session.id);
if (!matchesExisting) {
await this.logout(token.sessionId);
removedIds.push(token.sessionId);
await this.removeSession(token.sessionId);
removed.push(this.convertToSessionSync(token));
}
}));
@ -211,13 +211,13 @@ export class AzureActiveDirectoryService {
} catch (e) {
Logger.error(e.message);
// if data is improperly formatted, remove all of it and send change event
removedIds = this._tokens.map(token => token.sessionId);
removed = this._tokens.map(this.convertToSessionSync);
this.clearSessions();
}
} else {
if (this._tokens.length) {
// Log out all, remove all local data
removedIds = this._tokens.map(token => token.sessionId);
removed = this._tokens.map(this.convertToSessionSync);
Logger.info('No stored keychain data, clearing local data');
this._tokens = [];
@ -230,11 +230,25 @@ export class AzureActiveDirectoryService {
}
}
if (addedIds.length || removedIds.length) {
onDidChangeSessions.fire({ added: addedIds, removed: removedIds, changed: [] });
if (added.length || removed.length) {
onDidChangeSessions.fire({ added: added, removed: removed, changed: [] });
}
}
/**
* Return a session object without checking for expiry and potentially refreshing.
* @param token The token information.
*/
private convertToSessionSync(token: IToken): MicrosoftAuthenticationSession {
return {
id: token.sessionId,
accessToken: token.accessToken!,
idToken: token.idToken,
account: token.account,
scopes: token.scope.split(' ')
};
}
private async convertToSession(token: IToken): Promise<MicrosoftAuthenticationSession> {
const resolvedTokens = await this.resolveAccessAndIdTokens(token);
return {
@ -286,7 +300,17 @@ export class AzureActiveDirectoryService {
return Promise.all(this._tokens.map(token => this.convertToSession(token)));
}
public async login(scope: string): Promise<vscode.AuthenticationSession> {
async getSessions(scopes?: string[]): Promise<vscode.AuthenticationSession[]> {
if (!scopes) {
return this.sessions;
}
const orderedScopes = scopes.sort().join(' ');
const matchingTokens = this._tokens.filter(token => token.scope === orderedScopes);
return Promise.all(matchingTokens.map(token => this.convertToSession(token)));
}
public async createSession(scope: string): Promise<vscode.AuthenticationSession> {
Logger.info('Logging in...');
if (!scope.includes('offline_access')) {
Logger.info('Warning: The \'offline_access\' scope was not included, so the generated token will not be able to be refreshed.');
@ -478,8 +502,8 @@ export class AzureActiveDirectoryService {
if (token.expiresIn) {
this._refreshTimeouts.set(token.sessionId, setTimeout(async () => {
try {
await this.refreshToken(token.refreshToken, scope, token.sessionId);
onDidChangeSessions.fire({ added: [], removed: [], changed: [token.sessionId] });
const refreshedToken = await this.refreshToken(token.refreshToken, scope, token.sessionId);
onDidChangeSessions.fire({ added: [], removed: [], changed: [this.convertToSessionSync(refreshedToken)] });
} catch (e) {
if (e.message === REFRESH_NETWORK_FAILURE) {
const didSucceedOnRetry = await this.handleRefreshNetworkError(token.sessionId, token.refreshToken, scope);
@ -487,8 +511,8 @@ export class AzureActiveDirectoryService {
this.pollForReconnect(token.sessionId, token.refreshToken, token.scope);
}
} else {
await this.logout(token.sessionId);
onDidChangeSessions.fire({ added: [], removed: [token.sessionId], changed: [] });
await this.removeSession(token.sessionId);
onDidChangeSessions.fire({ added: [], removed: [this.convertToSessionSync(token)], changed: [] });
}
}
}, 1000 * (token.expiresIn - 30)));
@ -613,13 +637,16 @@ export class AzureActiveDirectoryService {
}
}
private removeInMemorySessionData(sessionId: string) {
private removeInMemorySessionData(sessionId: string): IToken | undefined {
const tokenIndex = this._tokens.findIndex(token => token.sessionId === sessionId);
let token: IToken | undefined;
if (tokenIndex > -1) {
token = this._tokens[tokenIndex];
this._tokens.splice(tokenIndex, 1);
}
this.clearSessionTimeout(sessionId);
return token;
}
private pollForReconnect(sessionId: string, refreshToken: string, scope: string): void {
@ -645,7 +672,7 @@ export class AzureActiveDirectoryService {
const token = this._tokens.find(token => token.sessionId === sessionId);
if (token) {
token.accessToken = undefined;
onDidChangeSessions.fire({ added: [], removed: [], changed: [token.sessionId] });
onDidChangeSessions.fire({ added: [], removed: [], changed: [this.convertToSessionSync(token)] });
}
}
@ -664,15 +691,21 @@ export class AzureActiveDirectoryService {
});
}
public async logout(sessionId: string) {
public async removeSession(sessionId: string): Promise<vscode.AuthenticationSession | undefined> {
Logger.info(`Logging out of session '${sessionId}'`);
this.removeInMemorySessionData(sessionId);
const token = this.removeInMemorySessionData(sessionId);
let session: vscode.AuthenticationSession | undefined;
if (token) {
session = this.convertToSessionSync(token);
}
if (this._tokens.length === 0) {
await this._keychain.deleteToken();
} else {
this.storeTokenData();
}
return session;
}
public async clearSessions() {

View File

@ -20,16 +20,16 @@ export async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.authentication.registerAuthenticationProvider('microsoft', 'Microsoft', {
onDidChangeSessions: onDidChangeSessions.event,
getSessions: () => Promise.resolve(loginService.sessions),
login: async (scopes: string[]) => {
getSessions: (scopes: string[]) => loginService.getSessions(scopes),
createSession: async (scopes: string[]) => {
try {
/* __GDPR__
"login" : { }
*/
telemetryReporter.sendTelemetryEvent('login');
const session = await loginService.login(scopes.sort().join(' '));
onDidChangeSessions.fire({ added: [session.id], removed: [], changed: [] });
const session = await loginService.createSession(scopes.sort().join(' '));
onDidChangeSessions.fire({ added: [session], removed: [], changed: [] });
return session;
} catch (e) {
/* __GDPR__
@ -40,15 +40,17 @@ export async function activate(context: vscode.ExtensionContext) {
throw e;
}
},
logout: async (id: string) => {
removeSession: async (id: string) => {
try {
/* __GDPR__
"logout" : { }
*/
telemetryReporter.sendTelemetryEvent('logout');
await loginService.logout(id);
onDidChangeSessions.fire({ added: [], removed: [id], changed: [] });
const session = await loginService.removeSession(id);
if (session) {
onDidChangeSessions.fire({ added: [], removed: [session], changed: [] });
}
} catch (e) {
/* __GDPR__
"logoutFailed" : { }