Path: blob/main/src/vs/workbench/contrib/authentication/browser/actions/manageDynamicAuthenticationProvidersAction.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 { localize, localize2 } from '../../../../../nls.js';6import { Action2 } from '../../../../../platform/actions/common/actions.js';7import { ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js';8import { IQuickInputService, IQuickPickItem } from '../../../../../platform/quickinput/common/quickInput.js';9import { IDynamicAuthenticationProviderStorageService, DynamicAuthenticationProviderInfo } from '../../../../services/authentication/common/dynamicAuthenticationProviderStorage.js';10import { IAuthenticationService } from '../../../../services/authentication/common/authentication.js';11import { IDialogService } from '../../../../../platform/dialogs/common/dialogs.js';1213interface IDynamicProviderQuickPickItem extends IQuickPickItem {14provider: DynamicAuthenticationProviderInfo;15}1617export class RemoveDynamicAuthenticationProvidersAction extends Action2 {1819static readonly ID = 'workbench.action.removeDynamicAuthenticationProviders';2021constructor() {22super({23id: RemoveDynamicAuthenticationProvidersAction.ID,24title: localize2('removeDynamicAuthProviders', 'Remove Dynamic Authentication Providers'),25category: localize2('authenticationCategory', 'Authentication'),26f1: true27});28}2930async run(accessor: ServicesAccessor): Promise<void> {31const quickInputService = accessor.get(IQuickInputService);32const dynamicAuthStorageService = accessor.get(IDynamicAuthenticationProviderStorageService);33const authenticationService = accessor.get(IAuthenticationService);34const dialogService = accessor.get(IDialogService);3536const interactedProviders = dynamicAuthStorageService.getInteractedProviders();3738if (interactedProviders.length === 0) {39await dialogService.info(40localize('noDynamicProviders', 'No dynamic authentication providers'),41localize('noDynamicProvidersDetail', 'No dynamic authentication providers have been used yet.')42);43return;44}4546const items: IDynamicProviderQuickPickItem[] = interactedProviders.map(provider => ({47label: provider.label,48description: localize('clientId', 'Client ID: {0}', provider.clientId),49provider50}));5152const selected = await quickInputService.pick(items, {53placeHolder: localize('selectProviderToRemove', 'Select a dynamic authentication provider to remove'),54canPickMany: true55});5657if (!selected || selected.length === 0) {58return;59}6061// Confirm deletion62const providerNames = selected.map(item => item.provider.label).join(', ');63const message = selected.length === 164? localize('confirmDeleteSingleProvider', 'Are you sure you want to remove the dynamic authentication provider "{0}"?', providerNames)65: localize('confirmDeleteMultipleProviders', 'Are you sure you want to remove {0} dynamic authentication providers: {1}?', selected.length, providerNames);6667const result = await dialogService.confirm({68message,69detail: 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.'),70primaryButton: localize('remove', 'Remove'),71type: 'warning'72});7374if (!result.confirmed) {75return;76}7778// Remove the selected providers79for (const item of selected) {80const providerId = item.provider.providerId;8182// Unregister from authentication service if still registered83if (authenticationService.isAuthenticationProviderRegistered(providerId)) {84authenticationService.unregisterAuthenticationProvider(providerId);85}8687// Remove from dynamic storage service88await dynamicAuthStorageService.removeDynamicProvider(providerId);89}90}91}929394