From 6545fed454fcdf1cc5f1f47fbd1cca14e72406b3 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 13 Jun 2022 03:05:03 -0400 Subject: [PATCH] Adds prompt to clear GitLab authentication --- src/git/remotes/gitlab.ts | 24 ++++++++++++++++++++++++ src/git/remotes/provider.ts | 7 ++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/git/remotes/gitlab.ts b/src/git/remotes/gitlab.ts index 96247a0..6b14a82 100644 --- a/src/git/remotes/gitlab.ts +++ b/src/git/remotes/gitlab.ts @@ -225,6 +225,30 @@ export class GitLabRemote extends RichRemoteProvider { return super.connect(); } + @log() + override disconnect(silent: boolean = false): void { + super.disconnect(silent); + + if (silent) return; + + async function promptToClearAuthentication(this: GitLabRemote) { + const clear = { title: 'Clear Authentication' }; + const cancel = { title: 'Cancel', isCloseAffordance: true }; + const result = await window.showWarningMessage( + `Rich integration with GitLab as been disconnected.\n\nDo you also want to clear your saved authentication?`, + { modal: true }, + clear, + cancel, + ); + + if (result === clear) { + void Container.instance.integrationAuthentication.deleteSession(this.id, this.authDescriptor); + } + } + + void promptToClearAuthentication.call(this); + } + async getLocalInfoFromRemoteUri( repository: Repository, uri: Uri, diff --git a/src/git/remotes/provider.ts b/src/git/remotes/provider.ts index 177a533..d9d08f2 100644 --- a/src/git/remotes/provider.ts +++ b/src/git/remotes/provider.ts @@ -14,6 +14,7 @@ import { configuration } from '../../configuration'; import { Container } from '../../container'; import { AuthenticationError, ProviderRequestClientError } from '../../errors'; import { Logger } from '../../logger'; +import type { IntegrationAuthenticationSessionDescriptor } from '../../plus/integrationAuthentication'; import { WorkspaceStorageKeys } from '../../storage'; import { gate } from '../../system/decorators/gate'; import { debug, log } from '../../system/decorators/log'; @@ -303,6 +304,10 @@ export abstract class RichRemoteProvider extends RemoteProvider { ); } + protected get authDescriptor(): IntegrationAuthenticationSessionDescriptor { + return { domain: this.domain, scopes: this.authProvider.scopes }; + } + abstract get apiBaseUrl(): string; protected abstract get authProvider(): { id: string; scopes: string[] }; @@ -590,7 +595,7 @@ export abstract class RichRemoteProvider extends RemoteProvider { if (container.integrationAuthentication.hasProvider(this.authProvider.id)) { session = await container.integrationAuthentication.getSession( this.authProvider.id, - { domain: this.domain, scopes: this.authProvider.scopes }, + this.authDescriptor, { createIfNeeded: createIfNeeded }, ); } else {