aps-agent/server/entry/dev-identity.ts

27 lines
1.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* A1 阶段的临时身份解析:固定一个开发用户。
*
* A4.1 身份上下文落地后,这里换成:浏览器读 JMS 会话 Cookie、桌面端读授权令牌,
* 两者都解析成同一个 Subject(协议文档第 3 节)。现在不校验任何凭据,只区分客户端形态。
*/
import type { IncomingHttpHeaders } from 'node:http';
import type { Subject } from '../app/subject.js';
export function resolveSubject(headers: IncomingHttpHeaders): Subject {
// 测试与多身份联调用:x-aps-user / x-aps-tenant 覆盖开发身份(A4.1 接真实登录后移除)
const header = (name: string): string => {
const value = headers[name];
return String(Array.isArray(value) ? value[0] : (value ?? '')).trim();
};
const devUser = header('x-aps-user');
const devTenant = header('x-aps-tenant');
const raw = headers['x-aps-client'];
const clientKind = String(Array.isArray(raw) ? raw[0] : (raw ?? '')).toLowerCase() === 'desktop' ? 'desktop' : 'browser';
return {
userId: devUser === '' ? 'dev-user' : devUser,
tenantId: devTenant === '' ? 'dev-tenant' : devTenant,
displayName: '开发用户',
clientKind,
};
}