gh auth: back to prod auth

This commit is contained in:
João Moreno 2021-04-21 15:00:19 +02:00
parent 5b7a28c43f
commit 034157dea8
No known key found for this signature in database
GPG key ID: 896B853774D1A575

View file

@ -15,7 +15,7 @@ const localize = nls.loadMessageBundle();
export const NETWORK_ERROR = 'network error';
const AUTH_RELAY_SERVER = 'vscode-auth.github.com';
const AUTH_RELAY_STAGING_SERVER = 'client-auth-staging-14a768b.herokuapp.com';
// const AUTH_RELAY_STAGING_SERVER = 'client-auth-staging-14a768b.herokuapp.com';
class UriEventHandler extends vscode.EventEmitter<vscode.Uri> implements vscode.UriHandler {
public handleUri(uri: vscode.Uri) {
@ -57,8 +57,8 @@ export class GitHubServer {
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' : ''}`));
const nocors = callbackUri.scheme === 'https' && /^vscode\./.test(callbackUri.authority);
callbackUri = await vscode.env.asExternalUri(vscode.Uri.parse(`${vscode.env.uriScheme}://vscode.github-authentication/did-authenticate${nocors ? '?nocors=true' : ''}`));
if (this.isTestEnvironment(callbackUri)) {
const token = await vscode.window.showInputBox({ prompt: 'GitHub Personal Access Token', ignoreFocusOut: true });
@ -85,7 +85,7 @@ export class GitHubServer {
const existingStates = this._pendingStates.get(scopes) || [];
this._pendingStates.set(scopes, [...existingStates, state]);
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' : ''}`);
const uri = vscode.Uri.parse(`https://${AUTH_RELAY_SERVER}/authorize/?callbackUri=${encodeURIComponent(callbackUri.toString())}&scope=${scopes}&state=${state}&responseType=code&authServer=https://github.com${nocors ? '&nocors=true' : ''}`);
await vscode.env.openExternal(uri);
}
@ -126,10 +126,12 @@ export class GitHubServer {
return;
}
const url = `https://${AUTH_RELAY_SERVER}/token?code=${code}&state=${query.state}`;
// TODO@joao: remove
if (query.staging) {
if (query.nocors) {
try {
const json: any = await vscode.commands.executeCommand('_workbench.fetchJSON', `https://${AUTH_RELAY_STAGING_SERVER}/token?code=${code}&state=${query.state}`, 'POST');
const json: any = await vscode.commands.executeCommand('_workbench.fetchJSON', url, 'POST');
Logger.info('Token exchange success!');
resolve(json.access_token);
} catch (err) {
@ -137,7 +139,7 @@ export class GitHubServer {
}
} else {
try {
const result = await fetch(`https://${AUTH_RELAY_SERVER}/token?code=${code}&state=${query.state}`, {
const result = await fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json'