Authorize default client team context
Build and deploy Docker image / build (push) Successful in 2m50s

This commit is contained in:
Ruslan Bakiev
2026-08-20 18:51:14 +07:00
parent 10cc93104a
commit 615f6615e0
+13 -5
View File
@@ -79,6 +79,12 @@ function scopesFromPayload(payload: JWTPayload): string[] {
return []; return [];
} }
function clientScopes(payload: JWTPayload): string[] {
return [
...new Set([...scopesFromPayload(payload), "teams:user", "teams:member"]),
];
}
function claimList(payload: JWTPayload, key: string): string[] { function claimList(payload: JWTPayload, key: string): string[] {
const value = (payload as Record<string, unknown>)[key]; const value = (payload as Record<string, unknown>)[key];
if (typeof value === "string") return value.split(" "); if (typeof value === "string") return value.split(" ");
@@ -115,12 +121,14 @@ export async function teamContext(req: FastifyRequest): Promise<AuthContext> {
audience: LOGTO_ORDERS_AUDIENCE, audience: LOGTO_ORDERS_AUDIENCE,
}); });
const teamUuid = (payload as Record<string, unknown>).team_uuid as const claimedTeamUuid = (payload as Record<string, unknown>).team_uuid;
| string const teamUuid =
| undefined; typeof claimedTeamUuid === "string" && claimedTeamUuid.length > 0
const scopes = scopesFromPayload(payload); ? claimedTeamUuid
: payload.sub;
const scopes = clientScopes(payload);
if (!teamUuid || !scopes.includes("teams:member")) { if (!payload.sub || !teamUuid) {
throw unauthenticated(); throw unauthenticated();
} }