Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreadman committed Sep 21, 2024
2 parents 3dbbecd + 2696410 commit 8423219
Show file tree
Hide file tree
Showing 87 changed files with 1,140 additions and 550 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@
"when": "hasNode",
"allow": [
"@parcel/watcher",
"@bpasero/watcher",
"@vscode/sqlite3",
"@vscode/vscode-languagedetection",
"@vscode/ripgrep",
Expand Down
6 changes: 0 additions & 6 deletions build/.moduleignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ node-pty/third_party/**
@parcel/watcher/src/**
!@parcel/watcher/build/Release/*.node

@bpasero/watcher/binding.gyp
@bpasero/watcher/build/**
@bpasero/watcher/prebuilds/**
@bpasero/watcher/src/**
!@bpasero/watcher/build/Release/*.node

vsda/build/**
vsda/ci/**
vsda/src/**
Expand Down
3 changes: 1 addition & 2 deletions build/gulpfile.scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ function nodeModules(destinationExe, destinationPdb, platform) {
// We don't build the prebuilt node files so we don't scan them
'!**/prebuilds/**/*.node',
// These are 3rd party modules that we should ignore
'!**/@parcel/watcher/**/*',
'!**/@bpasero/watcher/**/*']))
'!**/@parcel/watcher/**/*']))
.pipe(gulp.dest(destinationExe));
};

Expand Down
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;
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

import { PublicClientApplication, AccountInfo, Configuration, SilentFlowRequest, AuthenticationResult, InteractiveRequest, LogLevel } from '@azure/msal-node';
import { Disposable, Memento, SecretStorage, LogOutputChannel, window, ProgressLocation, l10n, EventEmitter } from 'vscode';
import { raceCancellationAndTimeoutError } from '../common/async';
import { Delayer, raceCancellationAndTimeoutError } from '../common/async';
import { SecretStorageCachePlugin } from '../common/cachePlugin';
import { MsalLoggerOptions } from '../common/loggerOptions';
import { ICachedPublicClientApplication } from '../common/publicClientCache';

export class CachedPublicClientApplication implements ICachedPublicClientApplication {
private _pca: PublicClientApplication;
private _sequencer = new Sequencer();
private readonly _refreshDelayer = new DelayerByKey<AuthenticationResult>();

private _accounts: AccountInfo[] = [];
private readonly _disposable: Disposable;
Expand Down Expand Up @@ -89,14 +90,15 @@ export class CachedPublicClientApplication implements ICachedPublicClientApplica
this._logger.debug(`[acquireTokenSilent] [${this._clientId}] [${this._authority}] [${request.scopes.join(' ')}] [${request.account.username}] got result`);
if (result.account && !result.fromCache) {
this._logger.debug(`[acquireTokenSilent] [${this._clientId}] [${this._authority}] [${request.scopes.join(' ')}] [${request.account.username}] firing event due to change`);
this._setupRefresh(result);
this._onDidAccountsChangeEmitter.fire({ added: [], changed: [result.account], deleted: [] });
}
return result;
}

async acquireTokenInteractive(request: InteractiveRequest): Promise<AuthenticationResult> {
this._logger.debug(`[acquireTokenInteractive] [${this._clientId}] [${this._authority}] [${request.scopes?.join(' ')}] loopbackClientOverride: ${request.loopbackClient ? 'true' : 'false'}`);
return await window.withProgress(
const result = await window.withProgress(
{
location: ProgressLocation.Notification,
cancellable: true,
Expand All @@ -108,6 +110,8 @@ export class CachedPublicClientApplication implements ICachedPublicClientApplica
1000 * 60 * 5
)
);
this._setupRefresh(result);
return result;
}

removeAccount(account: AccountInfo): Promise<void> {
Expand Down Expand Up @@ -149,6 +153,25 @@ export class CachedPublicClientApplication implements ICachedPublicClientApplica
}
this._logger.debug(`[update] [${this._clientId}] [${this._authority}] CachedPublicClientApplication update complete`);
}

private _setupRefresh(result: AuthenticationResult) {
const on = result.refreshOn || result.expiresOn;
if (!result.account || !on) {
return;
}

const account = result.account;
const scopes = result.scopes;
const timeToRefresh = on.getTime() - Date.now() - 5 * 60 * 1000; // 5 minutes before expiry
const key = JSON.stringify({ accountId: account.homeAccountId, scopes });
this._logger.debug(`[_setupRefresh] [${this._clientId}] [${this._authority}] [${scopes.join(' ')}] [${account.username}] timeToRefresh: ${timeToRefresh}`);
this._refreshDelayer.trigger(
key,
// This may need the redirectUri when we switch to the broker
() => this.acquireTokenSilent({ account, scopes, redirectUri: undefined, forceRefresh: true }),
timeToRefresh > 0 ? timeToRefresh : 0
);
}
}

export class Sequencer {
Expand All @@ -159,3 +182,17 @@ export class Sequencer {
return this.current = this.current.then(() => promiseTask(), () => promiseTask());
}
}

class DelayerByKey<T> {
private _delayers = new Map<string, Delayer<T>>();

trigger(key: string, fn: () => Promise<T>, delay: number): Promise<T> {
let delayer = this._delayers.get(key);
if (!delayer) {
delayer = new Delayer<T>(delay);
this._delayers.set(key, delayer);
}

return delayer.trigger(fn, delay);
}
}
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;
115 changes: 38 additions & 77 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "code-oss-dev",
"version": "1.94.0",
"distro": "d585f343487e2d902bca110c91ce9140ed79633c",
"distro": "0e2e9472d115a44f86c2cc3ea26fcea692643ec3",
"author": {
"name": "Microsoft Corporation"
},
Expand Down Expand Up @@ -75,7 +75,6 @@
"@microsoft/1ds-core-js": "^3.2.13",
"@microsoft/1ds-post-js": "^3.2.13",
"@parcel/watcher": "2.1.0",
"@bpasero/watcher": "https://github.com/bpasero/watcher.git#3e5e50c275590703f3eb46fac777b720e515d0d5",
"@vscode/deviceid": "^0.1.1",
"@vscode/iconv-lite-umd": "0.7.0",
"@vscode/policy-watcher": "^1.1.4",
Expand All @@ -89,14 +88,14 @@
"@vscode/windows-mutex": "^0.5.0",
"@vscode/windows-process-tree": "^0.6.0",
"@vscode/windows-registry": "^1.1.0",
"@xterm/addon-clipboard": "0.2.0-beta.39",
"@xterm/addon-image": "0.9.0-beta.56",
"@xterm/addon-search": "0.16.0-beta.56",
"@xterm/addon-serialize": "0.14.0-beta.56",
"@xterm/addon-unicode11": "0.9.0-beta.56",
"@xterm/addon-webgl": "0.19.0-beta.56",
"@xterm/headless": "5.6.0-beta.56",
"@xterm/xterm": "5.6.0-beta.56",
"@xterm/addon-clipboard": "^0.2.0-beta.47",
"@xterm/addon-image": "^0.9.0-beta.64",
"@xterm/addon-search": "^0.16.0-beta.64",
"@xterm/addon-serialize": "^0.14.0-beta.64",
"@xterm/addon-unicode11": "^0.9.0-beta.64",
"@xterm/addon-webgl": "^0.19.0-beta.64",
"@xterm/headless": "^5.6.0-beta.64",
"@xterm/xterm": "^5.6.0-beta.64",
"http-proxy-agent": "^7.0.0",
"https-proxy-agent": "^7.0.2",
"jschardet": "3.1.3",
Expand Down Expand Up @@ -200,9 +199,9 @@
"mocha-multi-reporters": "^1.5.1",
"npm-run-all": "^4.1.5",
"opn": "^6.0.0",
"os-browserify": "^0.3.0",
"p-all": "^1.0.0",
"path-browserify": "^1.0.1",
"os-browserify": "^0.3.0",
"postcss": "^8.4.33",
"postcss-nesting": "^12.0.2",
"pump": "^1.0.1",
Expand Down
Loading

0 comments on commit 8423219

Please sign in to comment.