Path: blob/main/src/vs/workbench/contrib/authentication/browser/actions/signOutOfAccountAction.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import Severity from '../../../../../base/common/severity.js';6import { localize } from '../../../../../nls.js';7import { Action2 } from '../../../../../platform/actions/common/actions.js';8import { IDialogService } from '../../../../../platform/dialogs/common/dialogs.js';9import { ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';10import { IAuthenticationAccessService } from '../../../../services/authentication/browser/authenticationAccessService.js';11import { IAuthenticationUsageService } from '../../../../services/authentication/browser/authenticationUsageService.js';12import { IAuthenticationService } from '../../../../services/authentication/common/authentication.js';1314export class SignOutOfAccountAction extends Action2 {15constructor() {16super({17id: '_signOutOfAccount',18title: localize('signOutOfAccount', "Sign out of account"),19f1: false20});21}2223override async run(accessor: ServicesAccessor, { providerId, accountLabel }: { providerId: string; accountLabel: string }): Promise<void> {24const authenticationService = accessor.get(IAuthenticationService);25const authenticationUsageService = accessor.get(IAuthenticationUsageService);26const authenticationAccessService = accessor.get(IAuthenticationAccessService);27const dialogService = accessor.get(IDialogService);2829if (!providerId || !accountLabel) {30throw new Error('Invalid arguments. Expected: { providerId: string; accountLabel: string }');31}3233const allSessions = await authenticationService.getSessions(providerId);34const sessions = allSessions.filter(s => s.account.label === accountLabel);3536const accountUsages = authenticationUsageService.readAccountUsages(providerId, accountLabel);3738const { confirmed } = await dialogService.confirm({39type: Severity.Info,40message: accountUsages.length41? localize('signOutMessage', "The account '{0}' has been used by: \n\n{1}\n\n Sign out from these extensions?", accountLabel, accountUsages.map(usage => usage.extensionName).join('\n'))42: localize('signOutMessageSimple', "Sign out of '{0}'?", accountLabel),43primaryButton: localize({ key: 'signOut', comment: ['&& denotes a mnemonic'] }, "&&Sign Out")44});4546if (confirmed) {47const removeSessionPromises = sessions.map(session => authenticationService.removeSession(providerId, session.id));48await Promise.all(removeSessionPromises);49authenticationUsageService.removeAccountUsage(providerId, accountLabel);50authenticationAccessService.removeAllowedExtensions(providerId, accountLabel);51}52}53}545556