3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { commands , env , ExtensionContext , l10n , window , workspace } from 'vscode' ;
6
+ import { commands , env , ExtensionContext , l10n , UIKind , Uri , window , workspace } from 'vscode' ;
7
7
import * as extensionV1 from './extensionV1' ;
8
8
import * as extensionV2 from './extensionV2' ;
9
9
import { createExperimentationService } from './common/experimentation' ;
@@ -34,11 +34,24 @@ function shouldUseMsal(expService: IExperimentationService): boolean {
34
34
return expValue ;
35
35
}
36
36
37
- Logger . info ( 'Acquired MSAL enablement value from default. Value: false ' ) ;
37
+ Logger . info ( 'Acquired MSAL enablement value from default. Value: true ' ) ;
38
38
// If no setting or experiment value is found, default to true
39
39
return true ;
40
40
}
41
41
42
+ function isSupportedWebClient ( uri : Uri ) : boolean {
43
+ return (
44
+ // vscode.dev & insiders.vscode.dev
45
+ / (?: ^ | \. ) v s c o d e \. d e v $ / . test ( uri . authority ) ||
46
+ // github.dev & codespaces
47
+ / (?: ^ | \. ) g i t h u b \. d e v $ / . test ( uri . authority ) ||
48
+ // localhost
49
+ / ^ l o c a l h o s t : \d + $ / . test ( uri . authority ) ||
50
+ // 127.0.0.1
51
+ / ^ 1 2 7 \. 0 \. 0 \. 1 : \d + $ / . test ( uri . authority )
52
+ ) ;
53
+ }
54
+
42
55
let useMsal : boolean | undefined ;
43
56
export async function activate ( context : ExtensionContext ) {
44
57
const mainTelemetryReporter = new MicrosoftAuthenticationTelemetryReporter ( context . extension . packageJSON . aiKey ) ;
@@ -47,6 +60,16 @@ export async function activate(context: ExtensionContext) {
47
60
mainTelemetryReporter ,
48
61
env . uriScheme !== 'vscode' , // isPreRelease
49
62
) ;
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
+
50
73
useMsal = shouldUseMsal ( expService ) ;
51
74
const clientIdVersion = workspace . getConfiguration ( 'microsoft-authentication' ) . get < 'v1' | 'v2' > ( 'clientIdVersion' , 'v1' ) ;
52
75
0 commit comments