From 33659eda9f03e6592798f5faad4e58af14a1d0c1 Mon Sep 17 00:00:00 2001 From: Rachel Macfarlane Date: Fri, 24 Jul 2020 12:38:43 -0700 Subject: [PATCH] Add codeExchangeProxyEndpoints to web api --- extensions/microsoft-authentication/src/AADHelper.ts | 5 ++++- .../authentication/browser/authenticationService.ts | 6 ++++++ src/vs/workbench/workbench.web.api.ts | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/extensions/microsoft-authentication/src/AADHelper.ts b/extensions/microsoft-authentication/src/AADHelper.ts index 670ebc6a0ce..f548b2ba528 100644 --- a/extensions/microsoft-authentication/src/AADHelper.ts +++ b/extensions/microsoft-authentication/src/AADHelper.ts @@ -471,7 +471,10 @@ export class AzureActiveDirectoryService { redirect_uri: redirectUrl }); - const result = await fetch(`${loginEndpointUrl}${tenant}/oauth2/v2.0/token`, { + const proxyEndpoints: { [providerId: string]: string } | undefined = await vscode.commands.executeCommand('workbench.getCodeExchangeProxyEndpoints'); + const endpoint = proxyEndpoints && proxyEndpoints['microsoft'] || `${loginEndpointUrl}${tenant}/oauth2/v2.0/token`; + + const result = await fetch(endpoint, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', diff --git a/src/vs/workbench/services/authentication/browser/authenticationService.ts b/src/vs/workbench/services/authentication/browser/authenticationService.ts index 9a176e4cae3..c7d73ff33f5 100644 --- a/src/vs/workbench/services/authentication/browser/authenticationService.ts +++ b/src/vs/workbench/services/authentication/browser/authenticationService.ts @@ -15,6 +15,7 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { CommandsRegistry } from 'vs/platform/commands/common/commands'; import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activity'; import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; +import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; export function getAuthenticationProviderActivationEvent(id: string): string { return `onAuthenticationRequest${id}`; } @@ -70,6 +71,11 @@ export interface SessionRequestInfo { [scopes: string]: SessionRequest; } +CommandsRegistry.registerCommand('workbench.getCodeExchangeProxyEndpoints', function (accessor, _) { + const environmentService = accessor.get(IWorkbenchEnvironmentService); + return environmentService.options?.codeExchangeProxyEndpoints; +}); + export class AuthenticationService extends Disposable implements IAuthenticationService { declare readonly _serviceBrand: undefined; private _placeholderMenuItem: IDisposable | undefined; diff --git a/src/vs/workbench/workbench.web.api.ts b/src/vs/workbench/workbench.web.api.ts index 40215a64939..7932149e035 100644 --- a/src/vs/workbench/workbench.web.api.ts +++ b/src/vs/workbench/workbench.web.api.ts @@ -345,6 +345,11 @@ interface IWorkbenchConstructionOptions { */ readonly driver?: boolean; + /** + * Endpoints to be used for proxying authentication code exchange calls in the browser. + */ + readonly codeExchangeProxyEndpoints?: { [providerId: string]: string } + //#endregion }