implement phase 5 และ fix bugs

This commit is contained in:
Suphonchai Phoonsawat 2026-08-19 23:06:57 +07:00
parent f4b1c3e14b
commit 1bb850c6b8
40 changed files with 1507 additions and 429 deletions

View file

@ -36,11 +36,17 @@ export function installFetchMock(
return fetchMock;
}
/** JWT ปลอมเพื่อ seed session — service อ่านแค่ claim `exp` */
export function makeFakeJwt(expiresAtMs: number, subject = "user-1"): string {
/** JWT ปลอมเพื่อ seed session — service อ่านแค่ claim `exp` / `sub` / `preferred_username` */
export function makeFakeJwt(
expiresAtMs: number,
subject = "user-1",
extraClaims: Record<string, unknown> = {}
): string {
const encode = (value: string): string =>
btoa(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
const header = encode(JSON.stringify({ alg: "RS256", typ: "JWT" }));
const payload = encode(JSON.stringify({ sub: subject, exp: Math.floor(expiresAtMs / 1000) }));
const payload = encode(
JSON.stringify({ sub: subject, exp: Math.floor(expiresAtMs / 1000), ...extraClaims })
);
return `${header}.${payload}.${encode("fake-signature")}`;
}