mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 16:49:06 +01:00
Depend on platform implementations for common features (#165950)
* don't depend on externals * remove unneeded externals
This commit is contained in:
committed by
GitHub
parent
1784a7ed34
commit
b9b93f2b45
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user