mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-20 00:04:14 +08:00
The flows are crucial to the extension and I wanted to be able to declare which can be used when in a declarative way. This reworks the flows into that model. Additionally, it pulls in the Client ID and secret from a config which will allow us to not rely on the vscode.dev proxy on Desktop (because we can make a distro change that includes the secret... which isn't a real secret, says GitHub)... unfortunately we still need to rely on it for Web due to CORS but we're in a position where it will be easy to rip the proxy out when GH supports it.
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
import { Uri } from 'vscode';
|
|
import { AuthProviderType } from '../github';
|
|
|
|
const VALID_DESKTOP_CALLBACK_SCHEMES = [
|
|
'vscode',
|
|
'vscode-insiders',
|
|
// 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.
|
|
// 'code-oss',
|
|
'vscode-wsl',
|
|
'vscode-exploration'
|
|
];
|
|
|
|
export function isSupportedClient(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)
|
|
);
|
|
}
|
|
|
|
export function isSupportedTarget(type: AuthProviderType, gheUri?: Uri): boolean {
|
|
return (
|
|
type === AuthProviderType.github ||
|
|
isHostedGitHubEnterprise(gheUri!)
|
|
);
|
|
}
|
|
|
|
export function isHostedGitHubEnterprise(uri: Uri): boolean {
|
|
return /\.ghe\.com$/.test(uri.authority);
|
|
}
|