Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/authentication/browser/actions/manageDynamicAuthenticationProvidersAction.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 { localize, localize2 } from '../../../../../nls.js';
7
import { Action2 } from '../../../../../platform/actions/common/actions.js';
8
import { ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';
9
import { IQuickInputService, IQuickPickItem } from '../../../../../platform/quickinput/common/quickInput.js';
10
import { IDynamicAuthenticationProviderStorageService, DynamicAuthenticationProviderInfo } from '../../../../services/authentication/common/dynamicAuthenticationProviderStorage.js';
11
import { IAuthenticationService } from '../../../../services/authentication/common/authentication.js';
12
import { IDialogService } from '../../../../../platform/dialogs/common/dialogs.js';
13
14
interface IDynamicProviderQuickPickItem extends IQuickPickItem {
15
provider: DynamicAuthenticationProviderInfo;
16
}
17
18
export class RemoveDynamicAuthenticationProvidersAction extends Action2 {
19
20
static readonly ID = 'workbench.action.removeDynamicAuthenticationProviders';
21
22
constructor() {
23
super({
24
id: RemoveDynamicAuthenticationProvidersAction.ID,
25
title: localize2('removeDynamicAuthProviders', 'Remove Dynamic Authentication Providers'),
26
category: localize2('authenticationCategory', 'Authentication'),
27
f1: true
28
});
29
}
30
31
async run(accessor: ServicesAccessor): Promise<void> {
32
const quickInputService = accessor.get(IQuickInputService);
33
const dynamicAuthStorageService = accessor.get(IDynamicAuthenticationProviderStorageService);
34
const authenticationService = accessor.get(IAuthenticationService);
35
const dialogService = accessor.get(IDialogService);
36
37
const interactedProviders = dynamicAuthStorageService.getInteractedProviders();
38
39
if (interactedProviders.length === 0) {
40
await dialogService.info(
41
localize('noDynamicProviders', 'No dynamic authentication providers'),
42
localize('noDynamicProvidersDetail', 'No dynamic authentication providers have been used yet.')
43
);
44
return;
45
}
46
47
const items: IDynamicProviderQuickPickItem[] = interactedProviders.map(provider => ({
48
label: provider.label,
49
description: localize('clientId', 'Client ID: {0}', provider.clientId),
50
provider
51
}));
52
53
const selected = await quickInputService.pick(items, {
54
placeHolder: localize('selectProviderToRemove', 'Select a dynamic authentication provider to remove'),
55
canPickMany: true
56
});
57
58
if (!selected || selected.length === 0) {
59
return;
60
}
61
62
// Confirm deletion
63
const providerNames = selected.map(item => item.provider.label).join(', ');
64
const message = selected.length === 1
65
? localize('confirmDeleteSingleProvider', 'Are you sure you want to remove the dynamic authentication provider "{0}"?', providerNames)
66
: localize('confirmDeleteMultipleProviders', 'Are you sure you want to remove {0} dynamic authentication providers: {1}?', selected.length, providerNames);
67
68
const result = await dialogService.confirm({
69
message,
70
detail: localize('confirmDeleteDetail', 'This will remove all stored authentication data for the selected provider(s). You will need to re-authenticate if you use these providers again.'),
71
primaryButton: localize('remove', 'Remove'),
72
type: 'warning'
73
});
74
75
if (!result.confirmed) {
76
return;
77
}
78
79
// Remove the selected providers
80
for (const item of selected) {
81
const providerId = item.provider.providerId;
82
83
// Unregister from authentication service if still registered
84
if (authenticationService.isAuthenticationProviderRegistered(providerId)) {
85
authenticationService.unregisterAuthenticationProvider(providerId);
86
}
87
88
// Remove from dynamic storage service
89
await dynamicAuthStorageService.removeDynamicProvider(providerId);
90
}
91
}
92
}
93
94