gh auth: fix staging server selection

This commit is contained in:
João Moreno 2021-04-21 10:06:21 +02:00
parent 479a224741
commit 3668a573ad
No known key found for this signature in database
GPG key ID: 896B853774D1A575

View file

@ -54,7 +54,11 @@ export class GitHubServer {
this.updateStatusBarItem(true);
const state = uuid();
const callbackUri = await vscode.env.asExternalUri(vscode.Uri.parse(`${vscode.env.uriScheme}://vscode.github-authentication/did-authenticate`));
let callbackUri = await vscode.env.asExternalUri(vscode.Uri.parse(`${vscode.env.uriScheme}://vscode.github-authentication/did-authenticate`));
// TODO@joaomoreno TODO@RMacfarlane
const staging = callbackUri.scheme === 'https' && /^vscode\./.test(callbackUri.authority);
callbackUri = await vscode.env.asExternalUri(vscode.Uri.parse(`${vscode.env.uriScheme}://vscode.github-authentication/did-authenticate${staging ? '?staging=true' : ''}`));
if (this.isTestEnvironment(callbackUri)) {
const token = await vscode.window.showInputBox({ prompt: 'GitHub Personal Access Token', ignoreFocusOut: true });
@ -81,8 +85,6 @@ export class GitHubServer {
const existingStates = this._pendingStates.get(scopes) || [];
this._pendingStates.set(scopes, [...existingStates, state]);
// TODO@joaomoreno TODO@RMacfarlane
const staging = callbackUri.scheme === 'https' && /^vscode\./.test(callbackUri.authority);
const uri = vscode.Uri.parse(`https://${staging ? AUTH_RELAY_STAGING_SERVER : AUTH_RELAY_SERVER}/authorize/?callbackUri=${encodeURIComponent(callbackUri.toString())}&scope=${scopes}&state=${state}&responseType=code&authServer=https://github.com${staging ? '&staging=true' : ''}`);
await vscode.env.openExternal(uri);
}