Compare commits
1
Commits
25e6053581
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7a41b2a24 |
+13
-5
@@ -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" },
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user