From 87ed97df8bb37ee2222f5494aca5c28e3c12ed8f Mon Sep 17 00:00:00 2001 From: Devraj Mehta Date: Fri, 17 Jan 2025 14:05:10 -0500 Subject: [PATCH] Use Electron fetch or Node fetch for github-authentication to support proxies (#238149) * Attempt to use Electron fetch for github-authentication Also changes fallback from node-fetch to the built-in Node fetch * Remove Content-Length header Electron compatibility It looks like it was set incorrectly to the body contents anyways. --- extensions/github-authentication/src/flows.ts | 2 -- extensions/github-authentication/src/node/fetch.ts | 9 +++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/extensions/github-authentication/src/flows.ts b/extensions/github-authentication/src/flows.ts index a2497b2b0b2..8920ea5d357 100644 --- a/extensions/github-authentication/src/flows.ts +++ b/extensions/github-authentication/src/flows.ts @@ -105,8 +105,6 @@ async function exchangeCodeForToken( headers: { Accept: 'application/json', 'Content-Type': 'application/x-www-form-urlencoded', - 'Content-Length': body.toString() - }, body: body.toString() }); diff --git a/extensions/github-authentication/src/node/fetch.ts b/extensions/github-authentication/src/node/fetch.ts index 58718078e69..ca344d436b1 100644 --- a/extensions/github-authentication/src/node/fetch.ts +++ b/extensions/github-authentication/src/node/fetch.ts @@ -2,6 +2,11 @@ * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import fetch from 'node-fetch'; -export const fetching = fetch; +let _fetch: typeof fetch; +try { + _fetch = require('electron').net.fetch; +} catch { + _fetch = fetch; +} +export const fetching = _fetch;