From f3399d690c474b1f61aa7eb6dfffb5f810b55d7f Mon Sep 17 00:00:00 2001 From: "EchoLayer Bot (Stag)" Date: Wed, 13 Mar 2024 18:39:43 +0000 Subject: [PATCH] The code block has been collapsed into a single line as requested. --- codex-vscode/src/services/oauth.service.ts | 31 +--------------------- 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/codex-vscode/src/services/oauth.service.ts b/codex-vscode/src/services/oauth.service.ts index a1e1e68a..441db398 100644 --- a/codex-vscode/src/services/oauth.service.ts +++ b/codex-vscode/src/services/oauth.service.ts @@ -15,36 +15,7 @@ export class OAuthService implements IOAuthService { * Initiates the flow of opening a browser window to allow the user to sign in to GitHub and authenticate with Codex * @returns {Promise} the jwt of the user we are authenticating through GitHub */ - public async authenticate(oAuthPath: OAuthPath): Promise { - const oAuthPlatform: OAuthPlatform = oAuthPath === OAuthPath.google ? OAuthPlatform.google : OAuthPlatform.github; - const ee = OAuthUrlHandler.getInstance().getEventEmitter(); - const uri = vscode.Uri.parse(`${process.env.API_URL}${oAuthPath}`); - - await vscode.env.openExternal(uri); - - // Register a single listener for the URI callback, in case the user starts the login process multiple times - // before completing it. - if (!OAuthService.codeExchangePromise) { - OAuthService.codeExchangePromise = promiseFromEvent( - ee.event, - this.postAuthorization() - ); - } - - return Promise.race([ - OAuthService.codeExchangePromise.promise, - new Promise((_, reject) => - setTimeout(() => { - // TODO we should make this alot simpler - this.clearCodeExchangePromise(); - reject({ - errorType: "cancelled", - errorMessage: `${oAuthPlatform} login cancelled`, - }); - }, 60000) - ), // wait 60 seconds for them to come back to the IDE - ]); - } + public async authenticate(oAuthPath: OAuthPath): Promise { const oAuthPlatform: OAuthPlatform = oAuthPath === OAuthPath.google ? OAuthPlatform.google : OAuthPlatform.github; const ee = OAuthUrlHandler.getInstance().getEventEmitter(); const uri = vscode.Uri.parse(`${process.env.API_URL}${oAuthPath}`); await vscode.env.openExternal(uri); if (!OAuthService.codeExchangePromise) { OAuthService.codeExchangePromise = promiseFromEvent(ee.event, this.postAuthorization()); } return Promise.race([OAuthService.codeExchangePromise.promise, new Promise((_, reject) => setTimeout(() => { this.clearCodeExchangePromise(); reject({ errorType: "cancelled", errorMessage: `${oAuthPlatform} login cancelled`, }); }, 60000))]); } // postAuthorization returns a function that is called from the promiseFromEvent function when the event is fired private postAuthorization: () => PromiseAdapter =