Authorize default client team context
Build and deploy Docker image / build (push) Successful in 3m13s
Build and deploy Docker image / build (push) Successful in 3m13s
This commit is contained in:
+13
-5
@@ -41,6 +41,12 @@ function scopesFromPayload(payload: JWTPayload): string[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
function clientScopes(payload: JWTPayload): string[] {
|
||||
return [
|
||||
...new Set([...scopesFromPayload(payload), "teams:user", "teams:member"]),
|
||||
];
|
||||
}
|
||||
|
||||
export async function m2mContext(): Promise<AuthContext> {
|
||||
return { scopes: [], isM2M: true };
|
||||
}
|
||||
@@ -52,12 +58,14 @@ export async function teamContext(req: FastifyRequest): Promise<AuthContext> {
|
||||
audience: LOGTO_BILLING_AUDIENCE,
|
||||
});
|
||||
|
||||
const teamUuid = (payload as Record<string, unknown>).team_uuid as
|
||||
| string
|
||||
| undefined;
|
||||
const scopes = scopesFromPayload(payload);
|
||||
const claimedTeamUuid = (payload as Record<string, unknown>).team_uuid;
|
||||
const teamUuid =
|
||||
typeof claimedTeamUuid === "string" && claimedTeamUuid.length > 0
|
||||
? claimedTeamUuid
|
||||
: payload.sub;
|
||||
const scopes = clientScopes(payload);
|
||||
|
||||
if (!teamUuid || !scopes.includes("teams:member")) {
|
||||
if (!payload.sub || !teamUuid) {
|
||||
throw new GraphQLError("Unauthorized", {
|
||||
extensions: { code: "UNAUTHENTICATED" },
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user