From d00f3edbec0f4980e06c7dd416d2ddf92c936ea8 Mon Sep 17 00:00:00 2001 From: Rachel Macfarlane Date: Mon, 6 Jul 2020 18:22:51 -0700 Subject: [PATCH] displayName -> label, use providerIds in favor of getProviderIds, #100993 --- .../github-authentication/src/github.ts | 9 +++-- .../microsoft-authentication/src/AADHelper.ts | 9 ++--- src/vs/editor/common/modes.ts | 2 +- src/vs/vscode.proposed.d.ts | 4 +-- .../api/browser/mainThreadAuthentication.ts | 20 +++++------ .../api/common/extHostAuthentication.ts | 33 ++++++++++++++----- src/vs/workbench/api/common/extHostTypes.ts | 2 +- .../parts/activitybar/activitybarActions.ts | 4 +-- .../contrib/url/browser/trustedDomains.ts | 2 +- .../browser/authenticationService.ts | 4 +-- .../browser/userDataSyncWorkbenchService.ts | 4 +-- 11 files changed, 57 insertions(+), 36 deletions(-) diff --git a/extensions/github-authentication/src/github.ts b/extensions/github-authentication/src/github.ts index 8aa1cb40480753..41acdff86bb7f9 100644 --- a/extensions/github-authentication/src/github.ts +++ b/extensions/github-authentication/src/github.ts @@ -14,7 +14,8 @@ export const onDidChangeSessions = new vscode.EventEmitter { const userInfo = await this._githubServer.getUserInfo(token); - return new vscode.AuthenticationSession(uuid(), token, { displayName: userInfo.accountName, id: userInfo.id }, scopes); + return new vscode.AuthenticationSession(uuid(), token, { label: userInfo.accountName, id: userInfo.id }, scopes); } private async setToken(session: vscode.AuthenticationSession): Promise { diff --git a/extensions/microsoft-authentication/src/AADHelper.ts b/extensions/microsoft-authentication/src/AADHelper.ts index 9f96e1003566d5..7894d3e31991a4 100644 --- a/extensions/microsoft-authentication/src/AADHelper.ts +++ b/extensions/microsoft-authentication/src/AADHelper.ts @@ -26,7 +26,7 @@ interface IToken { refreshToken: string; account: { - displayName: string; + label: string; id: string; }; scope: string; @@ -48,7 +48,8 @@ interface IStoredSession { refreshToken: string; scope: string; // Scopes are alphabetized and joined with a space account: { - displayName: string, + label?: string; + displayName?: string, id: string } } @@ -101,7 +102,7 @@ export class AzureActiveDirectoryService { accessToken: undefined, refreshToken: session.refreshToken, account: { - displayName: session.account.displayName, + label: session.account.label ?? session.account.displayName!, id: session.account.id }, scope: session.scope, @@ -437,7 +438,7 @@ export class AzureActiveDirectoryService { scope, sessionId: existingId || `${claims.tid}/${(claims.oid || (claims.altsecid || '' + claims.ipd || ''))}/${uuid()}`, account: { - displayName: claims.email || claims.unique_name || 'user@example.com', + label: claims.email || claims.unique_name || 'user@example.com', id: `${claims.tid}/${(claims.oid || (claims.altsecid || '' + claims.ipd || ''))}` } }; diff --git a/src/vs/editor/common/modes.ts b/src/vs/editor/common/modes.ts index 88c9caf5fe32f0..557b8e5b040886 100644 --- a/src/vs/editor/common/modes.ts +++ b/src/vs/editor/common/modes.ts @@ -1413,7 +1413,7 @@ export interface AuthenticationSession { id: string; accessToken: string; account: { - displayName: string; + label: string; id: string; } scopes: ReadonlyArray; diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 84ba37ce730cc9..7015e3d1d5e798 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -52,7 +52,7 @@ declare module 'vscode' { /** * The human-readable name of the account. */ - readonly displayName: string; + readonly label: string; /** * The unique identifier of the account. @@ -175,13 +175,13 @@ declare module 'vscode' { export const onDidChangeAuthenticationProviders: Event; /** + * @deprecated * The ids of the currently registered authentication providers. * @returns An array of the ids of authentication providers that are currently registered. */ export function getProviderIds(): Thenable>; /** - * @deprecated * An array of the ids of authentication providers that are currently registered. */ export const providerIds: ReadonlyArray; diff --git a/src/vs/workbench/api/browser/mainThreadAuthentication.ts b/src/vs/workbench/api/browser/mainThreadAuthentication.ts index f7d90a25e0dabf..dfb07a94bd419d 100644 --- a/src/vs/workbench/api/browser/mainThreadAuthentication.ts +++ b/src/vs/workbench/api/browser/mainThreadAuthentication.ts @@ -135,17 +135,17 @@ export class MainThreadAuthenticationProvider extends Disposable { } private registerSession(session: modes.AuthenticationSession) { - this._sessions.set(session.id, session.account.displayName); + this._sessions.set(session.id, session.account.label); - const existingSessionsForAccount = this._accounts.get(session.account.displayName); + const existingSessionsForAccount = this._accounts.get(session.account.label); if (existingSessionsForAccount) { - this._accounts.set(session.account.displayName, existingSessionsForAccount.concat(session.id)); + this._accounts.set(session.account.label, existingSessionsForAccount.concat(session.id)); return; } else { - this._accounts.set(session.account.displayName, [session.id]); + this._accounts.set(session.account.label, [session.id]); } - this.storageKeysSyncRegistryService.registerStorageKey({ key: `${this.id}-${session.account.displayName}`, version: 1 }); + this.storageKeysSyncRegistryService.registerStorageKey({ key: `${this.id}-${session.account.label}`, version: 1 }); } async signOut(accountName: string): Promise { @@ -273,7 +273,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu if (sessions.length) { if (!this.authenticationService.supportsMultipleAccounts(providerId)) { const session = sessions[0]; - const allowed = await this.$getSessionsPrompt(providerId, session.account.displayName, label, extensionId, extensionName); + const allowed = await this.$getSessionsPrompt(providerId, session.account.label, label, extensionId, extensionName); if (allowed) { return session; } else { @@ -292,7 +292,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu } const session = await this.authenticationService.login(providerId, scopes); - await this.$setTrustedExtension(providerId, session.account.displayName, extensionId, extensionName); + await this.$setTrustedExtension(providerId, session.account.label, extensionId, extensionName); return session; } else { await this.$requestNewSession(providerId, scopes, extensionId, extensionName); @@ -313,7 +313,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu if (existingSessionPreference) { const matchingSession = potentialSessions.find(session => session.id === existingSessionPreference); if (matchingSession) { - const allowed = await this.$getSessionsPrompt(providerId, matchingSession.account.displayName, providerName, extensionId, extensionName); + const allowed = await this.$getSessionsPrompt(providerId, matchingSession.account.label, providerName, extensionId, extensionName); if (allowed) { return matchingSession; } @@ -326,7 +326,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu quickPick.ignoreFocusOut = true; const items: { label: string, session?: modes.AuthenticationSession }[] = potentialSessions.map(session => { return { - label: session.account.displayName, + label: session.account.label, session }; }); @@ -351,7 +351,7 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu const session = selected.session ?? await this.authenticationService.login(providerId, scopes); - const accountName = session.account.displayName; + const accountName = session.account.label; const allowList = readAllowedExtensions(this.storageService, providerId, accountName); if (!allowList.find(allowed => allowed.id === extensionId)) { diff --git a/src/vs/workbench/api/common/extHostAuthentication.ts b/src/vs/workbench/api/common/extHostAuthentication.ts index ae19b1d0a5d285..cc9e9d35c7fb39 100644 --- a/src/vs/workbench/api/common/extHostAuthentication.ts +++ b/src/vs/workbench/api/common/extHostAuthentication.ts @@ -14,6 +14,8 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape { private _proxy: MainThreadAuthenticationShape; private _authenticationProviders: Map = new Map(); + private _providerIds: string[] = []; + private _onDidChangeAuthenticationProviders = new Emitter(); readonly onDidChangeAuthenticationProviders: Event = this._onDidChangeAuthenticationProviders.event; @@ -29,12 +31,7 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape { } get providerIds(): string[] { - const ids: string[] = []; - this._authenticationProviders.forEach(provider => { - ids.push(provider.id); - }); - - return ids; + return this._providerIds; } private async resolveSessions(providerId: string): Promise> { @@ -72,7 +69,7 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape { if (sessions.length) { if (!provider.supportsMultipleAccounts) { const session = sessions[0]; - const allowed = await this._proxy.$getSessionsPrompt(providerId, session.account.displayName, provider.label, extensionId, extensionName); + const allowed = await this._proxy.$getSessionsPrompt(providerId, session.account.label, provider.label, extensionId, extensionName); if (allowed) { return session; } else { @@ -91,7 +88,7 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape { } const session = await provider.login(scopes); - await this._proxy.$setTrustedExtension(providerId, session.account.displayName, extensionId, extensionName); + await this._proxy.$setTrustedExtension(providerId, session.account.label, extensionId, extensionName); return session; } else { await this._proxy.$requestNewSession(providerId, scopes, extensionId, extensionName); @@ -115,6 +112,9 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape { } this._authenticationProviders.set(provider.id, provider); + if (!this._providerIds.includes(provider.id)) { + this._providerIds.push(provider.id); + } const listener = provider.onDidChangeSessions(e => { this._proxy.$sendDidChangeSessions(provider.id, e); @@ -125,6 +125,10 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape { return new Disposable(() => { listener.dispose(); this._authenticationProviders.delete(provider.id); + const index = this._providerIds.findIndex(id => id === provider.id); + if (index > -1) { + this._providerIds.splice(index); + } this._proxy.$unregisterAuthenticationProvider(provider.id); }); } @@ -177,6 +181,19 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape { } $onDidChangeAuthenticationProviders(added: string[], removed: string[]) { + added.forEach(id => { + if (!this._providerIds.includes(id)) { + this._providerIds.push(id); + } + }); + + removed.forEach(id => { + const index = this._providerIds.findIndex(provider => provider === id); + if (index > -1) { + this._providerIds.splice(index); + } + }); + this._onDidChangeAuthenticationProviders.fire({ added, removed }); return Promise.resolve(); } diff --git a/src/vs/workbench/api/common/extHostTypes.ts b/src/vs/workbench/api/common/extHostTypes.ts index dd31d87042ae69..80e6800171e525 100644 --- a/src/vs/workbench/api/common/extHostTypes.ts +++ b/src/vs/workbench/api/common/extHostTypes.ts @@ -2770,7 +2770,7 @@ export enum ExtensionMode { //#region Authentication export class AuthenticationSession implements vscode.AuthenticationSession { - constructor(public id: string, public accessToken: string, public account: { displayName: string, id: string }, public scopes: string[]) { } + constructor(public id: string, public accessToken: string, public account: { label: string, id: string }, public scopes: string[]) { } } //#endregion Authentication diff --git a/src/vs/workbench/browser/parts/activitybar/activitybarActions.ts b/src/vs/workbench/browser/parts/activitybar/activitybarActions.ts index e81e4527ec3904..0ecdca45469dd7 100644 --- a/src/vs/workbench/browser/parts/activitybar/activitybarActions.ts +++ b/src/vs/workbench/browser/parts/activitybar/activitybarActions.ts @@ -141,7 +141,7 @@ export class AccountsActionViewItem extends ActivityActionViewItem { const providers = this.authenticationService.getProviderIds(); const allSessions = providers.map(async id => { const sessions = await this.authenticationService.getSessions(id); - const uniqueSessions = distinct(sessions, session => session.account.displayName); + const uniqueSessions = distinct(sessions, session => session.account.label); return { providerId: id, sessions: uniqueSessions @@ -153,7 +153,7 @@ export class AccountsActionViewItem extends ActivityActionViewItem { result.forEach(sessionInfo => { const providerDisplayName = this.authenticationService.getLabel(sessionInfo.providerId); sessionInfo.sessions.forEach(session => { - const accountName = session.account.displayName; + const accountName = session.account.label; const menu = new ContextSubMenu(`${accountName} (${providerDisplayName})`, [ new Action(`configureSessions${accountName}`, nls.localize('manageTrustedExtensions', "Manage Trusted Extensions"), '', true, _ => { return this.authenticationService.manageTrustedExtensionsForAccount(sessionInfo.providerId, accountName); diff --git a/src/vs/workbench/contrib/url/browser/trustedDomains.ts b/src/vs/workbench/contrib/url/browser/trustedDomains.ts index e8711813ff9a28..9f71f4b6f4bd09 100644 --- a/src/vs/workbench/contrib/url/browser/trustedDomains.ts +++ b/src/vs/workbench/contrib/url/browser/trustedDomains.ts @@ -185,7 +185,7 @@ export async function readTrustedDomains(accessor: ServicesAccessor) { const userDomains = authenticationService.isAuthenticationProviderRegistered('github') ? ((await authenticationService.getSessions('github')) ?? []) - .map(session => session.account.displayName) + .map(session => session.account.label) .filter((v, i, a) => a.indexOf(v) === i) .map(username => `https://github.com/${username}/`) : []; diff --git a/src/vs/workbench/services/authentication/browser/authenticationService.ts b/src/vs/workbench/services/authentication/browser/authenticationService.ts index 22247c9904c2d4..77eb1921f5d845 100644 --- a/src/vs/workbench/services/authentication/browser/authenticationService.ts +++ b/src/vs/workbench/services/authentication/browser/authenticationService.ts @@ -255,10 +255,10 @@ export class AuthenticationService extends Disposable implements IAuthentication const session = await authenticationService.login(providerId, scopes); // Add extension to allow list since user explicitly signed in on behalf of it - const allowList = readAllowedExtensions(storageService, providerId, session.account.displayName); + const allowList = readAllowedExtensions(storageService, providerId, session.account.label); if (!allowList.find(allowed => allowed.id === extensionId)) { allowList.push({ id: extensionId, name: extensionName }); - storageService.store(`${providerId}-${session.account.displayName}`, JSON.stringify(allowList), StorageScope.GLOBAL); + storageService.store(`${providerId}-${session.account.label}`, JSON.stringify(allowList), StorageScope.GLOBAL); } // And also set it as the preferred account for the extension diff --git a/src/vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService.ts b/src/vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService.ts index 9d479364190be7..568e65afa3498d 100644 --- a/src/vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService.ts +++ b/src/vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService.ts @@ -49,7 +49,7 @@ class UserDataSyncAccount implements IUserDataSyncAccount { constructor(readonly authenticationProviderId: string, private readonly session: AuthenticationSession) { } get sessionId(): string { return this.session.id; } - get accountName(): string { return this.session.account.displayName; } + get accountName(): string { return this.session.account.label; } get accountId(): string { return this.session.account.id; } get token(): string { return this.session.accessToken; } } @@ -305,7 +305,7 @@ export class UserDataSyncWorkbenchService extends Disposable implements IUserDat if (isAuthenticationProvider(result)) { const session = await this.authenticationService.login(result.id, result.scopes); sessionId = session.id; - accountName = session.account.displayName; + accountName = session.account.label; accountId = session.account.id; } else { sessionId = result.sessionId;