Compare commits

..
1 Commits
Author SHA1 Message Date
Ruslan Bakiev a7a41b2a24 Authorize default client team context
Build and deploy Docker image / build (push) Successful in 3m13s
2026-08-20 18:52:07 +07:00
+13 -5
View File
@@ -41,6 +41,12 @@ function scopesFromPayload(payload: JWTPayload): string[] {
return []; return [];
} }
function clientScopes(payload: JWTPayload): string[] {
return [
...new Set([...scopesFromPayload(payload), "teams:user", "teams:member"]),
];
}
export async function m2mContext(): Promise<AuthContext> { export async function m2mContext(): Promise<AuthContext> {
return { scopes: [], isM2M: true }; return { scopes: [], isM2M: true };
} }
@@ -52,12 +58,14 @@ export async function teamContext(req: FastifyRequest): Promise<AuthContext> {
audience: LOGTO_BILLING_AUDIENCE, audience: LOGTO_BILLING_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 new GraphQLError("Unauthorized", { throw new GraphQLError("Unauthorized", {
extensions: { code: "UNAUTHENTICATED" }, extensions: { code: "UNAUTHENTICATED" },
}); });