Skip to content

Commit

Permalink
Use Electron fetch to get Proxy settings properly (#229202)
Browse files Browse the repository at this point in the history
* Attempt to use Electron fetch

* Remove Content-Length header because electron doesn't like it

"Apparently Chromium doesn’t want the caller to set content-length, but will set it itself."
  • Loading branch information
TylerLeonhardt authored Sep 20, 2024
1 parent da4d466 commit f26394d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = withBrowserDefaults({
alias: {
'./node/authServer': path.resolve(__dirname, 'src/browser/authServer'),
'./node/buffer': path.resolve(__dirname, 'src/browser/buffer'),
'./node/fetch': path.resolve(__dirname, 'src/browser/fetch'),
'./node/authProvider': path.resolve(__dirname, 'src/browser/authProvider'),
}
}
Expand Down
6 changes: 3 additions & 3 deletions extensions/microsoft-authentication/src/AADHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { generateCodeChallenge, generateCodeVerifier, randomUUID } from './crypt
import { BetterTokenStorage, IDidChangeInOtherWindowEvent } from './betterSecretStorage';
import { LoopbackAuthServer } from './node/authServer';
import { base64Decode } from './node/buffer';
import fetch from './node/fetch';
import { UriEventHandler } from './UriEventHandler';
import TelemetryReporter from '@vscode/extension-telemetry';
import { Environment } from '@azure/ms-rest-azure-env';
Expand Down Expand Up @@ -805,11 +806,10 @@ export class AzureActiveDirectoryService {
let result;
let errorMessage: string | undefined;
try {
result = await fetch(endpoint, {
result = await fetch(endpoint.toString(), {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postData.length.toString()
'Content-Type': 'application/x-www-form-urlencoded'
},
body: postData
});
Expand Down
6 changes: 6 additions & 0 deletions extensions/microsoft-authentication/src/browser/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

export default fetch;
12 changes: 12 additions & 0 deletions extensions/microsoft-authentication/src/node/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

let _fetch: typeof fetch;
try {
_fetch = require('electron').net.fetch;
} catch {
_fetch = fetch;
}
export default _fetch;

0 comments on commit f26394d

Please sign in to comment.