Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 1 addition & 30 deletions codex-vscode/src/services/oauth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>} the jwt of the user we are authenticating through GitHub
*/
public async authenticate(oAuthPath: OAuthPath): Promise<UserInfo | ErrorResponse> {
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<ErrorResponse>((_, 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<UserInfo | ErrorResponse> { 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<ErrorResponse>((_, 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<vscode.Uri, UserInfo> =
Expand Down