Forward verified bearer identity to backend

This commit is contained in:
2569718930@qq.com
2026-06-14 03:29:52 +08:00
parent 5d0f2d4505
commit 2752156473
3 changed files with 62 additions and 3 deletions
@@ -343,7 +343,7 @@ export function runTests() {
assert(
backendAuthSource.includes("headers.set(FORWARDED_SUPABASE_USER_ID_HEADER") &&
backendAuthSource.includes("headers.set(FORWARDED_SUPABASE_EMAIL_HEADER") &&
backendAuthSource.indexOf("headers.set(FORWARDED_SUPABASE_USER_ID_HEADER") >
backendAuthSource.lastIndexOf("headers.set(FORWARDED_SUPABASE_USER_ID_HEADER") >
backendAuthSource.indexOf("const sessionUser = session?.user"),
"backend proxy must forward Supabase session user id/email with the backend token so Python can skip duplicate /auth/v1/user validation",
);
@@ -37,4 +37,17 @@ export function runTests() {
helperSource.includes('result.set("Content-Type", "application/json")'),
"backend auth must expose a safe JSON header builder",
);
assert(
helperSource.includes("getVerifiedBearerIdentity") &&
helperSource.includes("/auth/v1/user") &&
helperSource.includes("apikey: anonKey") &&
helperSource.includes("incomingAuth") &&
helperSource.includes("const identity = await getVerifiedBearerIdentity(incomingAuth)") &&
helperSource.includes("headers.set(FORWARDED_SUPABASE_USER_ID_HEADER, identity.userId)") &&
helperSource.includes("headers.set(FORWARDED_SUPABASE_EMAIL_HEADER, identity.email)") &&
helperSource.includes("authUserId: identity?.userId || null") &&
helperSource.includes("authEmail: identity?.email || null"),
"backend auth helper must verify incoming Supabase bearer tokens and forward trusted user identity headers to backend services",
);
}