4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
6
import * as vscode from 'vscode' ;
7
- import fetch , { Response } from 'node-fetch' ;
8
- import { v4 as uuid } from 'uuid' ;
7
+ import * as path from 'path' ;
9
8
import { PromiseAdapter , promiseFromEvent } from './common/utils' ;
10
- import { ExperimentationTelemetry } from './experimentationService' ;
9
+ import { ExperimentationTelemetry } from './common/ experimentationService' ;
11
10
import { AuthProviderType , UriEventHandler } from './github' ;
12
11
import { Log } from './common/logger' ;
13
12
import { isSupportedEnvironment } from './common/env' ;
14
- import { LoopbackAuthServer } from './authServer' ;
15
- import path = require( 'path' ) ;
13
+ import { LoopbackAuthServer } from './node/authServer' ;
14
+ import { crypto } from './node/crypto' ;
15
+ import { fetching } from './node/fetch' ;
16
16
17
17
const CLIENT_ID = '01ab8ac9400c4e429b23' ;
18
18
const GITHUB_TOKEN_URL = 'https://vscode.dev/codeExchangeProxyEndpoints/github/login/oauth/access_token' ;
@@ -38,7 +38,7 @@ interface IGitHubDeviceCodeResponse {
38
38
async function getScopes ( token : string , serverUri : vscode . Uri , logger : Log ) : Promise < string [ ] > {
39
39
try {
40
40
logger . info ( 'Getting token scopes...' ) ;
41
- const result = await fetch ( serverUri . toString ( ) , {
41
+ const result = await fetching ( serverUri . toString ( ) , {
42
42
headers : {
43
43
Authorization : `token ${ token } ` ,
44
44
'User-Agent' : 'Visual-Studio-Code'
@@ -99,7 +99,7 @@ export class GitHubServer implements IGitHubServer {
99
99
return this . _redirectEndpoint ;
100
100
} else {
101
101
// GHES
102
- const result = await fetch ( this . getServerUri ( '/meta' ) . toString ( true ) ) ;
102
+ const result = await fetching ( this . getServerUri ( '/meta' ) . toString ( true ) ) ;
103
103
if ( result . ok ) {
104
104
try {
105
105
const json : { installed_version : string } = await result . json ( ) ;
@@ -151,7 +151,7 @@ export class GitHubServer implements IGitHubServer {
151
151
}
152
152
} ;
153
153
154
- const nonce = uuid ( ) ;
154
+ const nonce : string = crypto . getRandomValues ( new Uint32Array ( 2 ) ) . reduce ( ( prev , curr ) => prev += curr . toString ( 16 ) , '' ) ;
155
155
const callbackUri = await vscode . env . asExternalUri ( vscode . Uri . parse ( `${ vscode . env . uriScheme } ://vscode.github-authentication/did-authenticate?nonce=${ encodeURIComponent ( nonce ) } ` ) ) ;
156
156
157
157
const supported = isSupportedEnvironment ( callbackUri ) ;
@@ -298,7 +298,7 @@ export class GitHubServer implements IGitHubServer {
298
298
path : '/login/device/code' ,
299
299
query : `client_id=${ CLIENT_ID } &scope=${ scopes } `
300
300
} ) ;
301
- const result = await fetch ( uri . toString ( true ) , {
301
+ const result = await fetching ( uri . toString ( true ) , {
302
302
method : 'POST' ,
303
303
headers : {
304
304
Accept : 'application/json'
@@ -382,7 +382,7 @@ export class GitHubServer implements IGitHubServer {
382
382
}
383
383
let accessTokenResult ;
384
384
try {
385
- accessTokenResult = await fetch ( refreshTokenUri . toString ( true ) , {
385
+ accessTokenResult = await fetching ( refreshTokenUri . toString ( true ) , {
386
386
method : 'POST' ,
387
387
headers : {
388
388
Accept : 'application/json'
@@ -452,7 +452,7 @@ export class GitHubServer implements IGitHubServer {
452
452
body . append ( 'github_enterprise' , this . baseUri . toString ( true ) ) ;
453
453
body . append ( 'redirect_uri' , await this . getRedirectEndpoint ( ) ) ;
454
454
}
455
- const result = await fetch ( endpointUrl , {
455
+ const result = await fetching ( endpointUrl , {
456
456
method : 'POST' ,
457
457
headers : {
458
458
Accept : 'application/json' ,
@@ -485,10 +485,10 @@ export class GitHubServer implements IGitHubServer {
485
485
}
486
486
487
487
public async getUserInfo ( token : string ) : Promise < { id : string ; accountName : string } > {
488
- let result : Response ;
488
+ let result ;
489
489
try {
490
490
this . _logger . info ( 'Getting user info...' ) ;
491
- result = await fetch ( this . getServerUri ( '/user' ) . toString ( ) , {
491
+ result = await fetching ( this . getServerUri ( '/user' ) . toString ( ) , {
492
492
headers : {
493
493
Authorization : `token ${ token } ` ,
494
494
'User-Agent' : 'Visual-Studio-Code'
@@ -544,7 +544,7 @@ export class GitHubServer implements IGitHubServer {
544
544
545
545
private async checkEduDetails ( token : string ) : Promise < void > {
546
546
try {
547
- const result = await fetch ( 'https://education.github.com/api/user' , {
547
+ const result = await fetching ( 'https://education.github.com/api/user' , {
548
548
headers : {
549
549
Authorization : `token ${ token } ` ,
550
550
'faculty-check-preview' : 'true' ,
@@ -577,7 +577,7 @@ export class GitHubServer implements IGitHubServer {
577
577
private async checkEnterpriseVersion ( token : string ) : Promise < void > {
578
578
try {
579
579
580
- const result = await fetch ( this . getServerUri ( '/meta' ) . toString ( ) , {
580
+ const result = await fetching ( this . getServerUri ( '/meta' ) . toString ( ) , {
581
581
headers : {
582
582
Authorization : `token ${ token } ` ,
583
583
'User-Agent' : 'Visual-Studio-Code'
0 commit comments