diff --git a/extensions/github-browser/src/github/api.ts b/extensions/github-browser/src/github/api.ts index 41eedc8fe39..bb2bb65cb6d 100644 --- a/extensions/github-browser/src/github/api.ts +++ b/extensions/github-browser/src/github/api.ts @@ -75,7 +75,7 @@ export class GitHubApi implements Disposable { if (!providers.includes('github')) { await new Promise(resolve => { authentication.onDidChangeAuthenticationProviders(e => { - if (e.added.includes('github')) { + if (e.added.find(provider => provider.id === 'github')) { resolve(); } }); diff --git a/src/vs/editor/common/modes.ts b/src/vs/editor/common/modes.ts index 557b8e5b040..b89285449aa 100644 --- a/src/vs/editor/common/modes.ts +++ b/src/vs/editor/common/modes.ts @@ -1428,6 +1428,14 @@ export interface AuthenticationSessionsChangeEvent { changed: ReadonlyArray; } +/** + * @internal + */ +export interface AuthenticationProviderInformation { + id: string; + label: string; +} + export interface Command { id: string; title: string; diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 18cfb14b5ee..457dc0deac7 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -49,15 +49,30 @@ declare module 'vscode' { * The information of an account associated with an authentication session. */ export interface AuthenticationSessionAccountInformation { - /** - * The human-readable name of the account. - */ - readonly label: string; - /** * The unique identifier of the account. */ readonly id: string; + + /** + * The human-readable name of the account. + */ + readonly label: string; + } + + /** + * Basic information about an[authenticationProvider](#AuthenticationProvider) + */ + export interface AuthenticationProviderInformation { + /** + * The unique identifier of the authentication provider. + */ + readonly id: string; + + /** + * The human-readable name of the authentication provider. + */ + readonly label: string; } /** @@ -67,12 +82,12 @@ declare module 'vscode' { /** * The ids of the [authenticationProvider](#AuthenticationProvider)s that have been added. */ - readonly added: ReadonlyArray; + readonly added: ReadonlyArray; /** * The ids of the [authenticationProvider](#AuthenticationProvider)s that have been removed. */ - readonly removed: ReadonlyArray; + readonly removed: ReadonlyArray; } /** @@ -91,6 +106,13 @@ declare module 'vscode' { clearSessionPreference?: boolean; } + export interface AuthenticationProviderAuthenticationSessionsChangeEvent extends AuthenticationSessionsChangeEvent { + /** + * The [authenticationProvider](#AuthenticationProvider) that has had its sessions change. + */ + readonly provider: AuthenticationProviderInformation; + } + /** * An [event](#Event) which fires when an [AuthenticationSession](#AuthenticationSession) is added, removed, or changed. */ @@ -182,10 +204,16 @@ declare module 'vscode' { export function getProviderIds(): Thenable>; /** + * @deprecated * An array of the ids of authentication providers that are currently registered. */ export const providerIds: ReadonlyArray; + /** + * An array of the information of authentication providers that are currently registered. + */ + export const providers: ReadonlyArray; + /** * Returns whether a provider has any sessions matching the requested scopes. This request * is transparent to the user, no UI is shown. Rejects if a provider with providerId is not @@ -235,7 +263,7 @@ declare module 'vscode' { * within a session has changed for a provider. Fires with the ids of the providers * that have had session data change. */ - export const onDidChangeSessions: Event<{ [providerId: string]: AuthenticationSessionsChangeEvent; }>; + export const onDidChangeSessions: Event; } //#endregion diff --git a/src/vs/workbench/api/browser/mainThreadAuthentication.ts b/src/vs/workbench/api/browser/mainThreadAuthentication.ts index dfb07a94bd4..878675c6f39 100644 --- a/src/vs/workbench/api/browser/mainThreadAuthentication.ts +++ b/src/vs/workbench/api/browser/mainThreadAuthentication.ts @@ -219,15 +219,15 @@ export class MainThreadAuthentication extends Disposable implements MainThreadAu this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostAuthentication); this._register(this.authenticationService.onDidChangeSessions(e => { - this._proxy.$onDidChangeAuthenticationSessions(e.providerId, e.event); + this._proxy.$onDidChangeAuthenticationSessions(e.providerId, e.label, e.event); })); - this._register(this.authenticationService.onDidRegisterAuthenticationProvider(providerId => { - this._proxy.$onDidChangeAuthenticationProviders([providerId], []); + this._register(this.authenticationService.onDidRegisterAuthenticationProvider(info => { + this._proxy.$onDidChangeAuthenticationProviders([info], []); })); - this._register(this.authenticationService.onDidUnregisterAuthenticationProvider(providerId => { - this._proxy.$onDidChangeAuthenticationProviders([], [providerId]); + this._register(this.authenticationService.onDidUnregisterAuthenticationProvider(info => { + this._proxy.$onDidChangeAuthenticationProviders([], [info]); })); } diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index a2f8e206c78..f358cc91e4f 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -202,6 +202,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I get providerIds(): string[] { return extHostAuthentication.providerIds; }, + get providers(): ReadonlyArray { + return extHostAuthentication.providers; + }, hasSessions(providerId: string, scopes: string[]): Thenable { return extHostAuthentication.hasSessions(providerId, scopes); }, @@ -211,7 +214,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I logout(providerId: string, sessionId: string): Thenable { return extHostAuthentication.logout(providerId, sessionId); }, - get onDidChangeSessions(): Event<{ [providerId: string]: vscode.AuthenticationSessionsChangeEvent }> { + get onDidChangeSessions(): Event { return extHostAuthentication.onDidChangeSessions; }, }; diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 394bdf82dcd..98dd1bcafcc 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1025,8 +1025,8 @@ export interface ExtHostAuthenticationShape { $getSessionAccessToken(id: string, sessionId: string): Promise; $login(id: string, scopes: string[]): Promise; $logout(id: string, sessionId: string): Promise; - $onDidChangeAuthenticationSessions(providerId: string, event: modes.AuthenticationSessionsChangeEvent): Promise; - $onDidChangeAuthenticationProviders(added: string[], removed: string[]): Promise; + $onDidChangeAuthenticationSessions(id: string, label: string, event: modes.AuthenticationSessionsChangeEvent): Promise; + $onDidChangeAuthenticationProviders(added: modes.AuthenticationProviderInformation[], removed: modes.AuthenticationProviderInformation[]): Promise; } export interface ExtHostSearchShape { diff --git a/src/vs/workbench/api/common/extHostAuthentication.ts b/src/vs/workbench/api/common/extHostAuthentication.ts index cc9e9d35c7f..45e533fa646 100644 --- a/src/vs/workbench/api/common/extHostAuthentication.ts +++ b/src/vs/workbench/api/common/extHostAuthentication.ts @@ -16,11 +16,13 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape { private _providerIds: string[] = []; + private _providers: vscode.AuthenticationProviderInformation[] = []; + private _onDidChangeAuthenticationProviders = new Emitter(); readonly onDidChangeAuthenticationProviders: Event = this._onDidChangeAuthenticationProviders.event; - private _onDidChangeSessions = new Emitter<{ [providerId: string]: vscode.AuthenticationSessionsChangeEvent }>(); - readonly onDidChangeSessions: Event<{ [providerId: string]: vscode.AuthenticationSessionsChangeEvent }> = this._onDidChangeSessions.event; + private _onDidChangeSessions = new Emitter(); + readonly onDidChangeSessions: Event = this._onDidChangeSessions.event; constructor(mainContext: IMainContext) { this._proxy = mainContext.getProxy(MainContext.MainThreadAuthentication); @@ -34,6 +36,10 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape { return this._providerIds; } + get providers(): ReadonlyArray { + return Object.freeze(this._providers); + } + private async resolveSessions(providerId: string): Promise> { const provider = this._authenticationProviders.get(providerId); @@ -116,6 +122,13 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape { this._providerIds.push(provider.id); } + if (!this._providers.find(p => p.id === provider.id)) { + this._providers.push({ + id: provider.id, + label: provider.label + }); + } + const listener = provider.onDidChangeSessions(e => { this._proxy.$sendDidChangeSessions(provider.id, e); }); @@ -129,6 +142,12 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape { if (index > -1) { this._providerIds.splice(index); } + + const i = this._providers.findIndex(p => p.id === provider.id); + if (i > -1) { + this._providers.splice(i); + } + this._proxy.$unregisterAuthenticationProvider(provider.id); }); } @@ -175,22 +194,22 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape { throw new Error(`Unable to find authentication provider with handle: ${providerId}`); } - $onDidChangeAuthenticationSessions(providerId: string, event: modes.AuthenticationSessionsChangeEvent) { - this._onDidChangeSessions.fire({ [providerId]: event }); + $onDidChangeAuthenticationSessions(id: string, label: string, event: modes.AuthenticationSessionsChangeEvent) { + this._onDidChangeSessions.fire({ provider: { id, label }, ...event }); return Promise.resolve(); } - $onDidChangeAuthenticationProviders(added: string[], removed: string[]) { + $onDidChangeAuthenticationProviders(added: modes.AuthenticationProviderInformation[], removed: modes.AuthenticationProviderInformation[]) { added.forEach(id => { - if (!this._providerIds.includes(id)) { - this._providerIds.push(id); + if (!this._providers.includes(id)) { + this._providers.push(id); } }); - removed.forEach(id => { - const index = this._providerIds.findIndex(provider => provider === id); + removed.forEach(p => { + const index = this._providers.findIndex(provider => provider.id === p.id); if (index > -1) { - this._providerIds.splice(index); + this._providers.splice(index); } }); diff --git a/src/vs/workbench/services/authentication/browser/authenticationService.ts b/src/vs/workbench/services/authentication/browser/authenticationService.ts index 77eb1921f5d..202a92003fa 100644 --- a/src/vs/workbench/services/authentication/browser/authenticationService.ts +++ b/src/vs/workbench/services/authentication/browser/authenticationService.ts @@ -6,7 +6,7 @@ import * as nls from 'vs/nls'; import { Emitter, Event } from 'vs/base/common/event'; import { Disposable, IDisposable } from 'vs/base/common/lifecycle'; -import { AuthenticationSession, AuthenticationSessionsChangeEvent } from 'vs/editor/common/modes'; +import { AuthenticationSession, AuthenticationSessionsChangeEvent, AuthenticationProviderInformation } from 'vs/editor/common/modes'; import { registerSingleton } from 'vs/platform/instantiation/common/extensions'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { MainThreadAuthenticationProvider } from 'vs/workbench/api/browser/mainThreadAuthentication'; @@ -28,10 +28,10 @@ export interface IAuthenticationService { requestNewSession(id: string, scopes: string[], extensionId: string, extensionName: string): void; sessionsUpdate(providerId: string, event: AuthenticationSessionsChangeEvent): void; - readonly onDidRegisterAuthenticationProvider: Event; - readonly onDidUnregisterAuthenticationProvider: Event; + readonly onDidRegisterAuthenticationProvider: Event; + readonly onDidUnregisterAuthenticationProvider: Event; - readonly onDidChangeSessions: Event<{ providerId: string, event: AuthenticationSessionsChangeEvent }>; + readonly onDidChangeSessions: Event<{ providerId: string, label: string, event: AuthenticationSessionsChangeEvent }>; getSessions(providerId: string): Promise>; getLabel(providerId: string): string; supportsMultipleAccounts(providerId: string): boolean; @@ -77,14 +77,14 @@ export class AuthenticationService extends Disposable implements IAuthentication private _authenticationProviders: Map = new Map(); - private _onDidRegisterAuthenticationProvider: Emitter = this._register(new Emitter()); - readonly onDidRegisterAuthenticationProvider: Event = this._onDidRegisterAuthenticationProvider.event; + private _onDidRegisterAuthenticationProvider: Emitter = this._register(new Emitter()); + readonly onDidRegisterAuthenticationProvider: Event = this._onDidRegisterAuthenticationProvider.event; - private _onDidUnregisterAuthenticationProvider: Emitter = this._register(new Emitter()); - readonly onDidUnregisterAuthenticationProvider: Event = this._onDidUnregisterAuthenticationProvider.event; + private _onDidUnregisterAuthenticationProvider: Emitter = this._register(new Emitter()); + readonly onDidUnregisterAuthenticationProvider: Event = this._onDidUnregisterAuthenticationProvider.event; - private _onDidChangeSessions: Emitter<{ providerId: string, event: AuthenticationSessionsChangeEvent }> = this._register(new Emitter<{ providerId: string, event: AuthenticationSessionsChangeEvent }>()); - readonly onDidChangeSessions: Event<{ providerId: string, event: AuthenticationSessionsChangeEvent }> = this._onDidChangeSessions.event; + private _onDidChangeSessions: Emitter<{ providerId: string, label: string, event: AuthenticationSessionsChangeEvent }> = this._register(new Emitter<{ providerId: string, label: string, event: AuthenticationSessionsChangeEvent }>()); + readonly onDidChangeSessions: Event<{ providerId: string, label: string, event: AuthenticationSessionsChangeEvent }> = this._onDidChangeSessions.event; constructor(@IActivityService private readonly activityService: IActivityService) { super(); @@ -134,7 +134,7 @@ export class AuthenticationService extends Disposable implements IAuthentication registerAuthenticationProvider(id: string, authenticationProvider: MainThreadAuthenticationProvider): void { this._authenticationProviders.set(id, authenticationProvider); - this._onDidRegisterAuthenticationProvider.fire(id); + this._onDidRegisterAuthenticationProvider.fire({ id, label: authenticationProvider.label }); if (this._placeholderMenuItem) { this._placeholderMenuItem.dispose(); @@ -149,7 +149,7 @@ export class AuthenticationService extends Disposable implements IAuthentication if (provider) { provider.dispose(); this._authenticationProviders.delete(id); - this._onDidUnregisterAuthenticationProvider.fire(id); + this._onDidUnregisterAuthenticationProvider.fire({ id, label: provider.label }); this.updateAccountsMenuItem(); } @@ -165,9 +165,9 @@ export class AuthenticationService extends Disposable implements IAuthentication } async sessionsUpdate(id: string, event: AuthenticationSessionsChangeEvent): Promise { - this._onDidChangeSessions.fire({ providerId: id, event: event }); const provider = this._authenticationProviders.get(id); if (provider) { + this._onDidChangeSessions.fire({ providerId: id, label: provider.label, event: event }); await provider.updateSessionItems(event); this.updateAccountsMenuItem(); diff --git a/src/vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService.ts b/src/vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService.ts index fecc3af3434..1f7767b9423 100644 --- a/src/vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService.ts +++ b/src/vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService.ts @@ -137,7 +137,7 @@ export class UserDataSyncWorkbenchService extends Disposable implements IUserDat Event.any( this.authenticationService.onDidRegisterAuthenticationProvider, this.authenticationService.onDidUnregisterAuthenticationProvider, - ), authenticationProviderId => this.isSupportedAuthenticationProviderId(authenticationProviderId)), + ), info => this.isSupportedAuthenticationProviderId(info.id)), Event.filter(this.userDataSyncAccountService.onTokenFailed, isSuccessive => !isSuccessive)) (() => this.update()));