Compare commits
1
Commits
10cc93104a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
615f6615e0 |
+13
-5
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user