From cfc6a123e7f3f3b98e2930836bdc242c8698e949 Mon Sep 17 00:00:00 2001 From: Rachel Macfarlane Date: Tue, 28 Apr 2020 17:32:49 -0700 Subject: [PATCH] Add logout method to auth provider API --- src/vs/vscode.proposed.d.ts | 8 ++++++++ src/vs/workbench/api/common/extHost.api.impl.ts | 3 +++ src/vs/workbench/api/common/extHostAuthentication.ts | 9 +++++++++ 3 files changed, 20 insertions(+) diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index b5d02bad111..858428aa1bf 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -128,6 +128,14 @@ declare module 'vscode' { */ export function login(providerId: string, scopes: string[]): Thenable; + /** + * Logout of a specific session. + * @param providerId The id of the provider to use + * @param sessionId The session id to remove + * provider + */ + export function logout(providerId: string, sessionId: string): Thenable; + /** * An [event](#Event) which fires when the array of sessions has changed, or data * within a session has changed for a provider. Fires with the ids of the providers diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 1fe058f7251..260b6468e9a 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 login(providerId: string, scopes: string[]): Thenable { return extHostAuthentication.login(extension, providerId, scopes); }, + logout(providerId: string, sessionId: string): Thenable { + return extHostAuthentication.logout(providerId, sessionId); + }, get onDidChangeSessions(): Event<{ [providerId: string]: vscode.AuthenticationSessionsChangeEvent }> { return extHostAuthentication.onDidChangeSessions; }, diff --git a/src/vs/workbench/api/common/extHostAuthentication.ts b/src/vs/workbench/api/common/extHostAuthentication.ts index 210a5dec82e..888aefea967 100644 --- a/src/vs/workbench/api/common/extHostAuthentication.ts +++ b/src/vs/workbench/api/common/extHostAuthentication.ts @@ -102,6 +102,15 @@ export class ExtHostAuthentication implements ExtHostAuthenticationShape { }; } + async logout(providerId: string, sessionId: string): Promise { + const provider = this._authenticationProviders.get(providerId); + if (!provider) { + throw new Error(`No authentication provider with id '${providerId}' is currently registered.`); + } + + return provider.logout(sessionId); + } + registerAuthenticationProvider(provider: vscode.AuthenticationProvider): vscode.Disposable { if (this._authenticationProviders.get(provider.id)) { throw new Error(`An authentication provider with id '${provider.id}' is already registered.`);