From 342a1f4f52ff8521cd6860a95a4408e51694dfdc Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Tue, 13 Dec 2022 17:18:25 -0800 Subject: [PATCH] Don't run the local server option if we are running in remote (#169076) Additionally improve the conditional for device code flow. ref #168338 --- extensions/github-authentication/src/github.ts | 3 +-- .../github-authentication/src/githubServer.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/extensions/github-authentication/src/github.ts b/extensions/github-authentication/src/github.ts index 055e3f16276..6dc6aceaae9 100644 --- a/extensions/github-authentication/src/github.ts +++ b/extensions/github-authentication/src/github.ts @@ -68,8 +68,7 @@ export class GitHubAuthenticationProvider implements vscode.AuthenticationProvid this._logger, this._telemetryReporter, uriHandler, - // We only can use the Device Code flow when we have a full node environment because of CORS. - context.extension.extensionKind === vscode.ExtensionKind.Workspace || vscode.env.uiKind === vscode.UIKind.Desktop, + context.extension.extensionKind, ghesUri); // Contains the current state of the sessions we have available. diff --git a/extensions/github-authentication/src/githubServer.ts b/extensions/github-authentication/src/githubServer.ts index e1f766d5dc4..f292b3a42dd 100644 --- a/extensions/github-authentication/src/githubServer.ts +++ b/extensions/github-authentication/src/githubServer.ts @@ -71,7 +71,7 @@ export class GitHubServer implements IGitHubServer { private readonly _logger: Log, private readonly _telemetryReporter: ExperimentationTelemetry, private readonly _uriHandler: UriEventHandler, - private readonly _supportDeviceCodeFlow: boolean, + private readonly _extensionKind: vscode.ExtensionKind, private readonly _ghesUri?: vscode.Uri ) { this._type = _ghesUri ? AuthProviderType.githubEnterprise : AuthProviderType.github; @@ -164,8 +164,13 @@ export class GitHubServer implements IGitHubServer { } } - // Starting a local server isn't supported in web - if (vscode.env.uiKind === vscode.UIKind.Desktop) { + // Starting a local server is only supported if: + // 1. We are in a UI extension because we need to open a port on the machine that has the browser + // 2. We are in a node runtime because we need to open a port on the machine + if ( + this._extensionKind === vscode.ExtensionKind.UI && + typeof navigator === 'undefined' + ) { try { await promptToContinue(); return await this.doLoginWithLocalServer(scopes); @@ -175,7 +180,8 @@ export class GitHubServer implements IGitHubServer { } } - if (this._supportDeviceCodeFlow) { + // We only can use the Device Code flow when we have a full node environment because of CORS. + if (typeof navigator === 'undefined') { try { await promptToContinue(); return await this.doLoginDeviceCodeFlow(scopes);