"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "extensions/microsoft-authentication/src/AADHelper.ts" between
vscode-1.50.0.tar.gz and vscode-1.50.1.tar.gz

About: Visual Studio Code is a source code editor (available for Windows, macOS and Linux). It comes with built-in support for JavaScript, TypeScript and Node.js and has extensions for other languages (such as C++, C#, Java, Python, PHP, Go). Source code.

AADHelper.ts  (vscode-1.50.0):AADHelper.ts  (vscode-1.50.1)
skipping to change at line 96 skipping to change at line 96
class UriEventHandler extends vscode.EventEmitter<vscode.Uri> implements vscode. UriHandler { class UriEventHandler extends vscode.EventEmitter<vscode.Uri> implements vscode. UriHandler {
public handleUri(uri: vscode.Uri) { public handleUri(uri: vscode.Uri) {
this.fire(uri); this.fire(uri);
} }
} }
export class AzureActiveDirectoryService { export class AzureActiveDirectoryService {
private _tokens: IToken[] = []; private _tokens: IToken[] = [];
private _refreshTimeouts: Map<string, NodeJS.Timeout> = new Map<string, N odeJS.Timeout>(); private _refreshTimeouts: Map<string, NodeJS.Timeout> = new Map<string, N odeJS.Timeout>();
private _uriHandler: UriEventHandler; private _uriHandler: UriEventHandler;
private _disposables: vscode.Disposable[] = [];
constructor() { constructor() {
this._uriHandler = new UriEventHandler(); this._uriHandler = new UriEventHandler();
vscode.window.registerUriHandler(this._uriHandler); this._disposables.push(vscode.window.registerUriHandler(this._uri Handler));
} }
public async initialize(): Promise<void> { public async initialize(): Promise<void> {
const storedData = await keychain.getToken(); const storedData = await keychain.getToken();
if (storedData) { if (storedData) {
try { try {
const sessions = this.parseStoredData(storedData) ; const sessions = this.parseStoredData(storedData) ;
const refreshes = sessions.map(async session => { const refreshes = sessions.map(async session => {
if (!session.refreshToken) { if (!session.refreshToken) {
return Promise.resolve(); return Promise.resolve();
skipping to change at line 143 skipping to change at line 144
} }
}); });
await Promise.all(refreshes); await Promise.all(refreshes);
} catch (e) { } catch (e) {
Logger.info('Failed to initialize stored data'); Logger.info('Failed to initialize stored data');
await this.clearSessions(); await this.clearSessions();
} }
} }
this.pollForChange(); this._disposables.push(vscode.authentication.onDidChangePassword( () => this.checkForUpdates));
} }
private parseStoredData(data: string): IStoredSession[] { private parseStoredData(data: string): IStoredSession[] {
return JSON.parse(data); return JSON.parse(data);
} }
private async storeTokenData(): Promise<void> { private async storeTokenData(): Promise<void> {
const serializedData: IStoredSession[] = this._tokens.map(token = > { const serializedData: IStoredSession[] = this._tokens.map(token = > {
return { return {
id: token.sessionId, id: token.sessionId,
refreshToken: token.refreshToken, refreshToken: token.refreshToken,
scope: token.scope, scope: token.scope,
account: token.account account: token.account
}; };
}); });
await keychain.setToken(JSON.stringify(serializedData)); await keychain.setToken(JSON.stringify(serializedData));
} }
private pollForChange() { private async checkForUpdates(): Promise<void> {
setTimeout(async () => { const addedIds: string[] = [];
const addedIds: string[] = []; let removedIds: string[] = [];
let removedIds: string[] = []; const storedData = await keychain.getToken();
const storedData = await keychain.getToken(); if (storedData) {
if (storedData) { try {
try { const sessions = this.parseStoredData(storedData)
const sessions = this.parseStoredData(sto ;
redData); let promises = sessions.map(async session => {
let promises = sessions.map(async session const matchesExisting = this._tokens.some
=> { (token => token.scope === session.scope && token.sessionId === session.id);
const matchesExisting = this._tok if (!matchesExisting && session.refreshTo
ens.some(token => token.scope === session.scope && token.sessionId === session.i ken) {
d); try {
if (!matchesExisting && session.r await this.refreshToken(s
efreshToken) { ession.refreshToken, session.scope, session.id);
try { addedIds.push(session.id)
await this.refres ;
hToken(session.refreshToken, session.scope, session.id); } catch (e) {
addedIds.push(ses if (e.message === REFRESH
sion.id); _NETWORK_FAILURE) {
} catch (e) { // Ignore, will a
if (e.message === utomatically retry on next poll.
REFRESH_NETWORK_FAILURE) { } else {
// Ignore await this.logout
, will automatically retry on next poll. (session.id);
} else {
await thi
s.logout(session.id);
}
} }
} }
}); }
});
promises = promises.concat(this._tokens.m
ap(async token => {
const matchesExisting = sessions.
some(session => token.scope === session.scope && token.sessionId === session.id)
;
if (!matchesExisting) {
await this.logout(token.s
essionId);
removedIds.push(token.ses
sionId);
}
}));
await Promise.all(promises); promises = promises.concat(this._tokens.map(async
} catch (e) { token => {
Logger.error(e.message); const matchesExisting = sessions.some(ses
// if data is improperly formatted, remov sion => token.scope === session.scope && token.sessionId === session.id);
e all of it and send change event if (!matchesExisting) {
removedIds = this._tokens.map(token => to await this.logout(token.sessionId
ken.sessionId); );
this.clearSessions(); removedIds.push(token.sessionId);
} }
} else { }));
if (this._tokens.length) {
// Log out all, remove all local data
removedIds = this._tokens.map(token => to
ken.sessionId);
Logger.info('No stored keychain data, cle
aring local data');
this._tokens = [];
this._refreshTimeouts.forEach(timeout =>
{
clearTimeout(timeout);
});
this._refreshTimeouts.clear(); await Promise.all(promises);
} } 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.sess
ionId);
this.clearSessions();
} }
} else {
if (this._tokens.length) {
// Log out all, remove all local data
removedIds = this._tokens.map(token => token.sess
ionId);
Logger.info('No stored keychain data, clearing lo
cal data');
this._tokens = [];
if (addedIds.length || removedIds.length) { this._refreshTimeouts.forEach(timeout => {
onDidChangeSessions.fire({ added: addedIds, remov clearTimeout(timeout);
ed: removedIds, changed: [] }); });
this._refreshTimeouts.clear();
} }
}
this.pollForChange(); if (addedIds.length || removedIds.length) {
}, 1000 * 30); onDidChangeSessions.fire({ added: addedIds, removed: remo
vedIds, changed: [] });
}
} }
private async convertToSession(token: IToken): Promise<vscode.Authenticat ionSession> { private async convertToSession(token: IToken): Promise<vscode.Authenticat ionSession> {
const resolvedToken = await this.resolveAccessToken(token); const resolvedToken = await this.resolveAccessToken(token);
return { return {
id: token.sessionId, id: token.sessionId,
accessToken: resolvedToken, accessToken: resolvedToken,
account: token.account, account: token.account,
scopes: token.scope.split(' ') scopes: token.scope.split(' ')
}; };
skipping to change at line 347 skipping to change at line 344
reject(e.message); reject(e.message);
} finally { } finally {
setTimeout(() => { setTimeout(() => {
server.close(); server.close();
}, 5000); }, 5000);
} }
}); });
} }
public dispose(): void {
this._disposables.forEach(disposable => disposable.dispose());
this._disposables = [];
}
private getCallbackEnvironment(callbackUri: vscode.Uri): string { private getCallbackEnvironment(callbackUri: vscode.Uri): string {
if (callbackUri.authority.endsWith('.workspaces.github.com') || c allbackUri.authority.endsWith('.github.dev')) { if (callbackUri.authority.endsWith('.workspaces.github.com') || c allbackUri.authority.endsWith('.github.dev')) {
return `${callbackUri.authority},`; return `${callbackUri.authority},`;
} }
switch (callbackUri.authority) { switch (callbackUri.authority) {
case 'online.visualstudio.com': case 'online.visualstudio.com':
return 'vso,'; return 'vso,';
case 'online-ppe.core.vsengsaas.visualstudio.com': case 'online-ppe.core.vsengsaas.visualstudio.com':
return 'vsoppe,'; return 'vsoppe,';
 End of changes. 12 change blocks. 
76 lines changed or deleted 73 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)