fix: canonicalize web auth principal
This commit is contained in:
@@ -79,7 +79,10 @@ async function handleRequest(request: IncomingMessage, response: ServerResponse)
|
||||
return json(response, 200, stateSummary());
|
||||
}
|
||||
|
||||
if (path === "/auth/session" || path === "/auth/bootstrap") return json(response, 200, authPayload());
|
||||
if (path === "/auth/session" || path === "/auth/bootstrap") {
|
||||
const payload = authPayload();
|
||||
return json(response, payload.authenticated === true ? 200 : 401, payload);
|
||||
}
|
||||
if (path === "/auth/login" && method === "POST") return authLoginResponse(response);
|
||||
if (path === "/v1/workbench/events" && method === "GET") return sse(response, url);
|
||||
if (path === "/v1/workbench/sessions" && method === "GET") {
|
||||
@@ -620,8 +623,12 @@ function isLegacyWorkbenchPath(path: string): boolean {
|
||||
}
|
||||
|
||||
function authPayload(): JsonRecord {
|
||||
if (state.scenarioId === "auth-upstream-unavailable" || state.scenarioId === "auth-invalid-credentials") return { authenticated: false, mode: "server", actor: null, user: null, expiresAt: null };
|
||||
return { authenticated: true, mode: "server", actor: { id: "usr_e2e_admin", username: "e2e-admin", role: "admin", status: "active" }, user: { id: "usr_e2e_admin", username: "e2e-admin", role: "admin", status: "active" }, expiresAt: null };
|
||||
const deniedCapabilities = { web: "forbidden", workbench: "forbidden", codeAgent: "forbidden", billing: "forbidden", apiKeys: "forbidden", admin: "forbidden" };
|
||||
if (state.scenarioId === "auth-upstream-unavailable" || state.scenarioId === "auth-invalid-credentials") {
|
||||
return { authenticated: false, mode: "server", authMethod: null, identityAuthority: null, sessionKind: null, actor: null, user: null, capabilities: deniedCapabilities, expiresAt: null, valuesRedacted: true, error: { code: "auth_required", message: "Authentication is required", status: 401 } };
|
||||
}
|
||||
const actor = { id: "usr_e2e_admin", username: "e2e-admin", role: "admin", status: "active" };
|
||||
return { authenticated: true, mode: "server", authMethod: "web-session", identityAuthority: "hwlab-local", sessionKind: "browser", actor, user: actor, capabilities: { web: "available", workbench: "available", codeAgent: "available", billing: "unlinked", apiKeys: "available", admin: "available" }, expiresAt: null, valuesRedacted: true };
|
||||
}
|
||||
|
||||
function authLoginResponse(response: ServerResponse): void {
|
||||
|
||||
Reference in New Issue
Block a user