From 62866e4fa562ae01f046b3dcb239f0af3407f9a6 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Tue, 29 Mar 2022 16:19:58 -0700 Subject: [PATCH] use URL class in a few places --- extensions/github-authentication/src/common/env.ts | 12 ++++++++---- extensions/github-authentication/src/githubServer.ts | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/extensions/github-authentication/src/common/env.ts b/extensions/github-authentication/src/common/env.ts index 2f6e7970313..6c3d893fabd 100644 --- a/extensions/github-authentication/src/common/env.ts +++ b/extensions/github-authentication/src/common/env.ts @@ -10,13 +10,17 @@ const VALID_DESKTOP_CALLBACK_SCHEMES = [ // On Windows, some browsers don't seem to redirect back to OSS properly. // As a result, you get stuck in the auth flow. We exclude this from the // list until we can figure out a way to fix this behavior in browsers. - // The behavior was experienced on Windows. // 'code-oss', 'vscode-wsl', 'vscode-exploration' ]; -// This comes from the GitHub Authentication server -export function isSupportedEnvironment(url: Uri): boolean { - return VALID_DESKTOP_CALLBACK_SCHEMES.includes(url.scheme) || url.authority.endsWith('vscode.dev') || url.authority.endsWith('github.dev'); +export function isSupportedEnvironment(uri: Uri): boolean { + return ( + VALID_DESKTOP_CALLBACK_SCHEMES.includes(uri.scheme) || + // vscode.dev & insiders.vscode.dev + /(?:^|\.)vscode\.dev$/.test(uri.authority) || + // github.dev & codespaces + /(?:^|\.)github\.dev$/.test(uri.authority) + ); } diff --git a/extensions/github-authentication/src/githubServer.ts b/extensions/github-authentication/src/githubServer.ts index 49a523b8f18..bcc8ca4e5ea 100644 --- a/extensions/github-authentication/src/githubServer.ts +++ b/extensions/github-authentication/src/githubServer.ts @@ -167,7 +167,10 @@ export class GitHubServer implements IGitHubServer { const proxyEndpoints: { [providerId: string]: string } | undefined = await vscode.commands.executeCommand('workbench.getCodeExchangeProxyEndpoints'); // If we are running in insiders vscode.dev, then ensure we use the redirect route on that. - const redirectUri = proxyEndpoints?.github?.includes('https://insiders.vscode.dev') ? REDIRECT_URL_INSIDERS : REDIRECT_URL_STABLE; + let redirectUri = REDIRECT_URL_STABLE; + if (proxyEndpoints?.github && new URL(proxyEndpoints.github).hostname === 'insiders.vscode.dev') { + redirectUri = REDIRECT_URL_INSIDERS; + } const searchParams = new URLSearchParams([ ['client_id', CLIENT_ID], ['redirect_uri', redirectUri],