Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/vscode.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler James Leonhardt <me@tylerleonhardt.com>2022-11-10 01:29:21 +0300
committerGitHub <noreply@github.com>2022-11-10 01:29:21 +0300
commitb9b93f2b45aa90e4d5f3b80351145d6f61203922 (patch)
treecf2609d1b52ebe29593d4a9306c11c1cb867167c
parent1784a7ed34aeddc9b4d21bbfa1531496e5873657 (diff)
Depend on platform implementations for common features (#165950)
* don't depend on externals * remove unneeded externals
-rw-r--r--extensions/github-authentication/extension-browser.webpack.config.js8
-rw-r--r--extensions/github-authentication/extension.webpack.config.js3
-rw-r--r--extensions/github-authentication/package.json4
-rw-r--r--extensions/github-authentication/src/browser/authServer.ts (renamed from extensions/github-authentication/src/env/browser/authServer.ts)0
-rw-r--r--extensions/github-authentication/src/browser/crypto.ts6
-rw-r--r--extensions/github-authentication/src/browser/fetch.ts6
-rw-r--r--extensions/github-authentication/src/common/experimentationService.ts (renamed from extensions/github-authentication/src/experimentationService.ts)0
-rw-r--r--extensions/github-authentication/src/github.ts8
-rw-r--r--extensions/github-authentication/src/githubServer.ts30
-rw-r--r--extensions/github-authentication/src/node/authServer.ts (renamed from extensions/github-authentication/src/authServer.ts)0
-rw-r--r--extensions/github-authentication/src/node/crypto.ts8
-rw-r--r--extensions/github-authentication/src/node/fetch.ts7
-rw-r--r--extensions/github-authentication/yarn.lock10
13 files changed, 50 insertions, 40 deletions
diff --git a/extensions/github-authentication/extension-browser.webpack.config.js b/extensions/github-authentication/extension-browser.webpack.config.js
index 4fa2d1aa902..37b207eb056 100644
--- a/extensions/github-authentication/extension-browser.webpack.config.js
+++ b/extensions/github-authentication/extension-browser.webpack.config.js
@@ -16,14 +16,12 @@ module.exports = withBrowserDefaults({
entry: {
extension: './src/extension.ts',
},
- externals: {
- 'keytar': 'commonjs keytar',
- },
resolve: {
alias: {
- 'node-fetch': path.resolve(__dirname, 'node_modules/node-fetch/browser.js'),
'uuid': path.resolve(__dirname, 'node_modules/uuid/dist/esm-browser/index.js'),
- './authServer': path.resolve(__dirname, 'src/env/browser/authServer'),
+ './node/authServer': path.resolve(__dirname, 'src/browser/authServer'),
+ './node/crypto': path.resolve(__dirname, 'src/browser/crypto'),
+ './node/fetch': path.resolve(__dirname, 'src/browser/fetch')
}
}
});
diff --git a/extensions/github-authentication/extension.webpack.config.js b/extensions/github-authentication/extension.webpack.config.js
index a513ac5c3b5..df3adb4ee7a 100644
--- a/extensions/github-authentication/extension.webpack.config.js
+++ b/extensions/github-authentication/extension.webpack.config.js
@@ -13,8 +13,5 @@ module.exports = withDefaults({
context: __dirname,
entry: {
extension: './src/extension.ts',
- },
- externals: {
- 'keytar': 'commonjs keytar'
}
});
diff --git a/extensions/github-authentication/package.json b/extensions/github-authentication/package.json
index 76bf2670bd1..2155a53e985 100644
--- a/extensions/github-authentication/package.json
+++ b/extensions/github-authentication/package.json
@@ -66,14 +66,12 @@
},
"dependencies": {
"node-fetch": "2.6.7",
- "uuid": "8.1.0",
"@vscode/extension-telemetry": "0.7.0-preview",
"vscode-tas-client": "^0.1.47"
},
"devDependencies": {
"@types/node": "16.x",
- "@types/node-fetch": "^2.5.7",
- "@types/uuid": "8.0.0"
+ "@types/node-fetch": "^2.5.7"
},
"repository": {
"type": "git",
diff --git a/extensions/github-authentication/src/env/browser/authServer.ts b/extensions/github-authentication/src/browser/authServer.ts
index 60b53c713a8..60b53c713a8 100644
--- a/extensions/github-authentication/src/env/browser/authServer.ts
+++ b/extensions/github-authentication/src/browser/authServer.ts
diff --git a/extensions/github-authentication/src/browser/crypto.ts b/extensions/github-authentication/src/browser/crypto.ts
new file mode 100644
index 00000000000..37a1b43361f
--- /dev/null
+++ b/extensions/github-authentication/src/browser/crypto.ts
@@ -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 const crypto = globalThis.crypto;
diff --git a/extensions/github-authentication/src/browser/fetch.ts b/extensions/github-authentication/src/browser/fetch.ts
new file mode 100644
index 00000000000..f7f69f1a1a1
--- /dev/null
+++ b/extensions/github-authentication/src/browser/fetch.ts
@@ -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 const fetching = fetch;
diff --git a/extensions/github-authentication/src/experimentationService.ts b/extensions/github-authentication/src/common/experimentationService.ts
index 16923309b4e..16923309b4e 100644
--- a/extensions/github-authentication/src/experimentationService.ts
+++ b/extensions/github-authentication/src/common/experimentationService.ts
diff --git a/extensions/github-authentication/src/github.ts b/extensions/github-authentication/src/github.ts
index 2255ac50eb0..055e3f16276 100644
--- a/extensions/github-authentication/src/github.ts
+++ b/extensions/github-authentication/src/github.ts
@@ -4,13 +4,13 @@
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
-import { v4 as uuid } from 'uuid';
+import TelemetryReporter from '@vscode/extension-telemetry';
import { Keychain } from './common/keychain';
import { GitHubServer, IGitHubServer } from './githubServer';
import { arrayEquals } from './common/utils';
-import { ExperimentationTelemetry } from './experimentationService';
-import TelemetryReporter from '@vscode/extension-telemetry';
+import { ExperimentationTelemetry } from './common/experimentationService';
import { Log } from './common/logger';
+import { crypto } from './node/crypto';
interface SessionData {
id: string;
@@ -286,7 +286,7 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid
private async tokenToSession(token: string, scopes: string[]): Promise<vscode.AuthenticationSession> {
const userInfo = await this._githubServer.getUserInfo(token);
return {
- id: uuid(),
+ id: crypto.getRandomValues(new Uint32Array(2)).reduce((prev, curr) => prev += curr.toString(16), ''),
accessToken: token,
account: { label: userInfo.accountName, id: userInfo.id },
scopes
diff --git a/extensions/github-authentication/src/githubServer.ts b/extensions/github-authentication/src/githubServer.ts
index 8ada06e784c..e1f766d5dc4 100644
--- a/extensions/github-authentication/src/githubServer.ts
+++ b/extensions/github-authentication/src/githubServer.ts
@@ -4,15 +4,15 @@
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
-import fetch, { Response } from 'node-fetch';
-import { v4 as uuid } from 'uuid';
+import * as path from 'path';
import { PromiseAdapter, promiseFromEvent } from './common/utils';
-import { ExperimentationTelemetry } from './experimentationService';
+import { ExperimentationTelemetry } from './common/experimentationService';
import { AuthProviderType, UriEventHandler } from './github';
import { Log } from './common/logger';
import { isSupportedEnvironment } from './common/env';
-import { LoopbackAuthServer } from './authServer';
-import path = require('path');
+import { LoopbackAuthServer } from './node/authServer';
+import { crypto } from './node/crypto';
+import { fetching } from './node/fetch';
const CLIENT_ID = '01ab8ac9400c4e429b23';
const GITHUB_TOKEN_URL = 'https://vscode.dev/codeExchangeProxyEndpoints/github/login/oauth/access_token';
@@ -38,7 +38,7 @@ interface IGitHubDeviceCodeResponse {
async function getScopes(token: string, serverUri: vscode.Uri, logger: Log): Promise<string[]> {
try {
logger.info('Getting token scopes...');
- const result = await fetch(serverUri.toString(), {
+ const result = await fetching(serverUri.toString(), {
headers: {
Authorization: `token ${token}`,
'User-Agent': 'Visual-Studio-Code'
@@ -99,7 +99,7 @@ export class GitHubServer implements IGitHubServer {
return this._redirectEndpoint;
} else {
// GHES
- const result = await fetch(this.getServerUri('/meta').toString(true));
+ const result = await fetching(this.getServerUri('/meta').toString(true));
if (result.ok) {
try {
const json: { installed_version: string } = await result.json();
@@ -151,7 +151,7 @@ export class GitHubServer implements IGitHubServer {
}
};
- const nonce = uuid();
+ const nonce: string = crypto.getRandomValues(new Uint32Array(2)).reduce((prev, curr) => prev += curr.toString(16), '');
const callbackUri = await vscode.env.asExternalUri(vscode.Uri.parse(`${vscode.env.uriScheme}://vscode.github-authentication/did-authenticate?nonce=${encodeURIComponent(nonce)}`));
const supported = isSupportedEnvironment(callbackUri);
@@ -298,7 +298,7 @@ export class GitHubServer implements IGitHubServer {
path: '/login/device/code',
query: `client_id=${CLIENT_ID}&scope=${scopes}`
});
- const result = await fetch(uri.toString(true), {
+ const result = await fetching(uri.toString(true), {
method: 'POST',
headers: {
Accept: 'application/json'
@@ -382,7 +382,7 @@ export class GitHubServer implements IGitHubServer {
}
let accessTokenResult;
try {
- accessTokenResult = await fetch(refreshTokenUri.toString(true), {
+ accessTokenResult = await fetching(refreshTokenUri.toString(true), {
method: 'POST',
headers: {
Accept: 'application/json'
@@ -452,7 +452,7 @@ export class GitHubServer implements IGitHubServer {
body.append('github_enterprise', this.baseUri.toString(true));
body.append('redirect_uri', await this.getRedirectEndpoint());
}
- const result = await fetch(endpointUrl, {
+ const result = await fetching(endpointUrl, {
method: 'POST',
headers: {
Accept: 'application/json',
@@ -485,10 +485,10 @@ export class GitHubServer implements IGitHubServer {
}
public async getUserInfo(token: string): Promise<{ id: string; accountName: string }> {
- let result: Response;
+ let result;
try {
this._logger.info('Getting user info...');
- result = await fetch(this.getServerUri('/user').toString(), {
+ result = await fetching(this.getServerUri('/user').toString(), {
headers: {
Authorization: `token ${token}`,
'User-Agent': 'Visual-Studio-Code'
@@ -544,7 +544,7 @@ export class GitHubServer implements IGitHubServer {
private async checkEduDetails(token: string): Promise<void> {
try {
- const result = await fetch('https://education.github.com/api/user', {
+ const result = await fetching('https://education.github.com/api/user', {
headers: {
Authorization: `token ${token}`,
'faculty-check-preview': 'true',
@@ -577,7 +577,7 @@ export class GitHubServer implements IGitHubServer {
private async checkEnterpriseVersion(token: string): Promise<void> {
try {
- const result = await fetch(this.getServerUri('/meta').toString(), {
+ const result = await fetching(this.getServerUri('/meta').toString(), {
headers: {
Authorization: `token ${token}`,
'User-Agent': 'Visual-Studio-Code'
diff --git a/extensions/github-authentication/src/authServer.ts b/extensions/github-authentication/src/node/authServer.ts
index de08c6fca0f..de08c6fca0f 100644
--- a/extensions/github-authentication/src/authServer.ts
+++ b/extensions/github-authentication/src/node/authServer.ts
diff --git a/extensions/github-authentication/src/node/crypto.ts b/extensions/github-authentication/src/node/crypto.ts
new file mode 100644
index 00000000000..367246fdbed
--- /dev/null
+++ b/extensions/github-authentication/src/node/crypto.ts
@@ -0,0 +1,8 @@
+/*---------------------------------------------------------------------------------------------
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ * Licensed under the MIT License. See License.txt in the project root for license information.
+ *--------------------------------------------------------------------------------------------*/
+
+import { webcrypto } from 'crypto';
+
+export const crypto = webcrypto as any as Crypto;
diff --git a/extensions/github-authentication/src/node/fetch.ts b/extensions/github-authentication/src/node/fetch.ts
new file mode 100644
index 00000000000..58718078e69
--- /dev/null
+++ b/extensions/github-authentication/src/node/fetch.ts
@@ -0,0 +1,7 @@
+/*---------------------------------------------------------------------------------------------
+ * 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;
diff --git a/extensions/github-authentication/yarn.lock b/extensions/github-authentication/yarn.lock
index a5d87294121..062ffe8f9d3 100644
--- a/extensions/github-authentication/yarn.lock
+++ b/extensions/github-authentication/yarn.lock
@@ -232,11 +232,6 @@
dependencies:
"@types/node" "*"
-"@types/uuid@8.0.0":
- version "8.0.0"
- resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.0.0.tgz#165aae4819ad2174a17476dbe66feebd549556c0"
- integrity sha512-xSQfNcvOiE5f9dyd4Kzxbof1aTrLobL278pGLKOZI6esGfZ7ts9Ka16CzIN6Y8hFHE1C7jIBZokULhK1bOgjRw==
-
"@vscode/extension-telemetry@0.7.0-preview":
version "0.7.0-preview"
resolved "https://registry.yarnpkg.com/@vscode/extension-telemetry/-/extension-telemetry-0.7.0-preview.tgz#2ff53a2b0d7f698724d610803cac9c4fb0058f90"
@@ -470,11 +465,6 @@ url-parse@^1.5.3:
querystringify "^2.1.1"
requires-port "^1.0.0"
-uuid@8.1.0:
- version "8.1.0"
- resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.1.0.tgz#6f1536eb43249f473abc6bd58ff983da1ca30d8d"
- integrity sha512-CI18flHDznR0lq54xBycOVmphdCYnQLKn8abKn7PXUiKUGdEd+/l9LWNJmugXel4hXq7S+RMNl34ecyC9TntWg==
-
uuid@^8.3.0:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"