Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/authentication/browser/actions/signOutOfAccountAction.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import Severity from '../../../../../base/common/severity.js';
7
import { localize } from '../../../../../nls.js';
8
import { Action2 } from '../../../../../platform/actions/common/actions.js';
9
import { IDialogService } from '../../../../../platform/dialogs/common/dialogs.js';
10
import { ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
11
import { IAuthenticationAccessService } from '../../../../services/authentication/browser/authenticationAccessService.js';
12
import { IAuthenticationUsageService } from '../../../../services/authentication/browser/authenticationUsageService.js';
13
import { IAuthenticationService } from '../../../../services/authentication/common/authentication.js';
14
15
export class SignOutOfAccountAction extends Action2 {
16
constructor() {
17
super({
18
id: '_signOutOfAccount',
19
title: localize('signOutOfAccount', "Sign out of account"),
20
f1: false
21
});
22
}
23
24
override async run(accessor: ServicesAccessor, { providerId, accountLabel }: { providerId: string; accountLabel: string }): Promise<void> {
25
const authenticationService = accessor.get(IAuthenticationService);
26
const authenticationUsageService = accessor.get(IAuthenticationUsageService);
27
const authenticationAccessService = accessor.get(IAuthenticationAccessService);
28
const dialogService = accessor.get(IDialogService);
29
30
if (!providerId || !accountLabel) {
31
throw new Error('Invalid arguments. Expected: { providerId: string; accountLabel: string }');
32
}
33
34
const allSessions = await authenticationService.getSessions(providerId);
35
const sessions = allSessions.filter(s => s.account.label === accountLabel);
36
37
const accountUsages = authenticationUsageService.readAccountUsages(providerId, accountLabel);
38
39
const { confirmed } = await dialogService.confirm({
40
type: Severity.Info,
41
message: accountUsages.length
42
? 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'))
43
: localize('signOutMessageSimple', "Sign out of '{0}'?", accountLabel),
44
primaryButton: localize({ key: 'signOut', comment: ['&& denotes a mnemonic'] }, "&&Sign Out")
45
});
46
47
if (confirmed) {
48
const removeSessionPromises = sessions.map(session => authenticationService.removeSession(providerId, session.id));
49
await Promise.all(removeSessionPromises);
50
authenticationUsageService.removeAccountUsage(providerId, accountLabel);
51
authenticationAccessService.removeAllowedExtensions(providerId, accountLabel);
52
}
53
}
54
}
55
56