Skip to content

Commit e72728b

Browse files
Disable MSAL for unsupported web clients (microsoft#239522)
Fall back to classic for unsupported web clients The actual fix to get these clients on MSAL is a little too large for a candidate: microsoft#239389 .. so for the candidate, we will simply detect this kind of client and go to the classic version of Microsoft auth. Fixes microsoft#238147
1 parent 14270fe commit e72728b

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

extensions/microsoft-authentication/src/extension.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { commands, env, ExtensionContext, l10n, window, workspace } from 'vscode';
6+
import { commands, env, ExtensionContext, l10n, UIKind, Uri, window, workspace } from 'vscode';
77
import * as extensionV1 from './extensionV1';
88
import * as extensionV2 from './extensionV2';
99
import { createExperimentationService } from './common/experimentation';
@@ -34,11 +34,24 @@ function shouldUseMsal(expService: IExperimentationService): boolean {
3434
return expValue;
3535
}
3636

37-
Logger.info('Acquired MSAL enablement value from default. Value: false');
37+
Logger.info('Acquired MSAL enablement value from default. Value: true');
3838
// If no setting or experiment value is found, default to true
3939
return true;
4040
}
4141

42+
function isSupportedWebClient(uri: Uri): boolean {
43+
return (
44+
// vscode.dev & insiders.vscode.dev
45+
/(?:^|\.)vscode\.dev$/.test(uri.authority) ||
46+
// github.dev & codespaces
47+
/(?:^|\.)github\.dev$/.test(uri.authority) ||
48+
// localhost
49+
/^localhost:\d+$/.test(uri.authority) ||
50+
// 127.0.0.1
51+
/^127\.0\.0\.1:\d+$/.test(uri.authority)
52+
);
53+
}
54+
4255
let useMsal: boolean | undefined;
4356
export async function activate(context: ExtensionContext) {
4457
const mainTelemetryReporter = new MicrosoftAuthenticationTelemetryReporter(context.extension.packageJSON.aiKey);
@@ -47,6 +60,16 @@ export async function activate(context: ExtensionContext) {
4760
mainTelemetryReporter,
4861
env.uriScheme !== 'vscode', // isPreRelease
4962
);
63+
64+
if (env.uiKind === UIKind.Web) {
65+
const callbackUri = await env.asExternalUri(Uri.parse(`${env.uriScheme}://vscode.microsoft-authentication`));
66+
if (!isSupportedWebClient(callbackUri)) {
67+
Logger.info('Unsupported web client. Falling back to classic auth.');
68+
await extensionV1.activate(context, mainTelemetryReporter.telemetryReporter);
69+
return;
70+
}
71+
}
72+
5073
useMsal = shouldUseMsal(expService);
5174
const clientIdVersion = workspace.getConfiguration('microsoft-authentication').get<'v1' | 'v2'>('clientIdVersion', 'v1');
5275

0 commit comments

Comments
 (0)