sessions - specific auth branding for auth redirect (#298277)

This commit is contained in:
Benjamin Pasero
2026-02-27 17:22:14 +01:00
committed by GitHub
parent 79d358e5ea
commit 77044e33d8
5 changed files with 43 additions and 8 deletions
@@ -7,7 +7,7 @@ import { URL } from 'url';
import * as fs from 'fs';
import * as path from 'path';
import { randomBytes } from 'crypto';
import { env } from 'vscode';
import { env, workspace } from 'vscode';
function sendFile(res: http.ServerResponse, filepath: string) {
const isSvg = filepath.endsWith('.svg');
@@ -99,13 +99,14 @@ export class LoopbackAuthServer implements ILoopbackServer {
this._resultPromise = new Promise<IOAuthResult>((resolve, reject) => deferred = { resolve, reject });
const appNameQueryParam = `&app_name=${encodeURIComponent(env.appName)}`;
const appIsSessionsQueryParam = workspace.isAgentSessionsWorkspace ? '&app_is_sessions=true' : '';
this._server = http.createServer((req, res) => {
const reqUrl = new URL(req.url!, `http://${req.headers.host}`);
switch (reqUrl.pathname) {
case '/signin': {
const receivedNonce = (reqUrl.searchParams.get('nonce') ?? '').replace(/ /g, '+');
if (receivedNonce !== this.nonce) {
res.writeHead(302, { location: `/?error=${encodeURIComponent('Nonce does not match.')}${appNameQueryParam}` });
res.writeHead(302, { location: `/?error=${encodeURIComponent('Nonce does not match.')}${appNameQueryParam}${appIsSessionsQueryParam}` });
res.end();
}
res.writeHead(302, { location: this._startingRedirect.toString() });
@@ -122,20 +123,20 @@ export class LoopbackAuthServer implements ILoopbackServer {
return;
}
if (this.state !== state) {
res.writeHead(302, { location: `/?error=${encodeURIComponent('State does not match.')}${appNameQueryParam}` });
res.writeHead(302, { location: `/?error=${encodeURIComponent('State does not match.')}${appNameQueryParam}${appIsSessionsQueryParam}` });
res.end();
throw new Error('State does not match.');
}
if (this.nonce !== nonce) {
res.writeHead(302, { location: `/?error=${encodeURIComponent('Nonce does not match.')}${appNameQueryParam}` });
res.writeHead(302, { location: `/?error=${encodeURIComponent('Nonce does not match.')}${appNameQueryParam}${appIsSessionsQueryParam}` });
res.end();
throw new Error('Nonce does not match.');
}
deferred.resolve({ code, state });
if (isPortable) {
res.writeHead(302, { location: `/?app_name=${encodeURIComponent(env.appName)}` });
res.writeHead(302, { location: `/?app_name=${encodeURIComponent(env.appName)}${appIsSessionsQueryParam}` });
} else {
res.writeHead(302, { location: `/?redirect_uri=${encodeURIComponent(callbackUri)}${appNameQueryParam}` });
res.writeHead(302, { location: `/?redirect_uri=${encodeURIComponent(callbackUri)}${appNameQueryParam}${appIsSessionsQueryParam}` });
}
res.end();
break;