Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/microsoft-authentication/src/extension.ts
3314 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 { commands, ExtensionContext, l10n, window, workspace } from 'vscode';
7
import * as extensionV1 from './extensionV1';
8
import * as extensionV2 from './extensionV2';
9
import { MicrosoftAuthenticationTelemetryReporter } from './common/telemetryReporter';
10
11
let implementation: 'msal' | 'msal-no-broker' | 'classic' = 'msal';
12
const getImplementation = () => workspace.getConfiguration('microsoft-authentication').get<'msal' | 'msal-no-broker' | 'classic'>('implementation') ?? 'msal';
13
14
export async function activate(context: ExtensionContext) {
15
const mainTelemetryReporter = new MicrosoftAuthenticationTelemetryReporter(context.extension.packageJSON.aiKey);
16
implementation = getImplementation();
17
context.subscriptions.push(workspace.onDidChangeConfiguration(async e => {
18
if (!e.affectsConfiguration('microsoft-authentication')) {
19
return;
20
}
21
if (implementation === getImplementation()) {
22
return;
23
}
24
25
// Allow for the migration to be re-attempted if the user switches back to the MSAL implementation
26
context.globalState.update('msalMigration', undefined);
27
28
const reload = l10n.t('Reload');
29
const result = await window.showInformationMessage(
30
'Reload required',
31
{
32
modal: true,
33
detail: l10n.t('Microsoft Account configuration has been changed.'),
34
},
35
reload
36
);
37
38
if (result === reload) {
39
commands.executeCommand('workbench.action.reloadWindow');
40
}
41
}));
42
const isNodeEnvironment = typeof process !== 'undefined' && typeof process?.versions?.node === 'string';
43
44
// Only activate the new extension if we are not running in a browser environment
45
if (!isNodeEnvironment) {
46
mainTelemetryReporter.sendActivatedWithClassicImplementationEvent('web');
47
return await extensionV1.activate(context, mainTelemetryReporter.telemetryReporter);
48
}
49
50
switch (implementation) {
51
case 'msal-no-broker':
52
mainTelemetryReporter.sendActivatedWithMsalNoBrokerEvent();
53
await extensionV2.activate(context, mainTelemetryReporter);
54
break;
55
case 'classic':
56
mainTelemetryReporter.sendActivatedWithClassicImplementationEvent('setting');
57
await extensionV1.activate(context, mainTelemetryReporter.telemetryReporter);
58
break;
59
case 'msal':
60
default:
61
await extensionV2.activate(context, mainTelemetryReporter);
62
break;
63
}
64
}
65
66
export function deactivate() {
67
if (implementation !== 'classic') {
68
extensionV2.deactivate();
69
} else {
70
extensionV1.deactivate();
71
}
72
}
73
74