This commit is contained in:
+8
-4
@@ -32,6 +32,10 @@ function scopesFromPayload(payload: JWTPayload): string[] {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clientScopes(payload: JWTPayload): string[] {
|
||||||
|
return [...new Set([...scopesFromPayload(payload), "teams:user"])];
|
||||||
|
}
|
||||||
|
|
||||||
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(" ");
|
||||||
@@ -57,12 +61,12 @@ export async function publicContext(req: FastifyRequest): Promise<AuthContext> {
|
|||||||
issuer: LOGTO_ISSUER,
|
issuer: LOGTO_ISSUER,
|
||||||
audience: LOGTO_KYC_AUDIENCE,
|
audience: LOGTO_KYC_AUDIENCE,
|
||||||
});
|
});
|
||||||
const scopes = scopesFromPayload(payload);
|
if (!payload.sub) {
|
||||||
if (!scopes.includes("teams:user")) {
|
|
||||||
throw new GraphQLError("Unauthorized", {
|
throw new GraphQLError("Unauthorized", {
|
||||||
extensions: { code: "UNAUTHENTICATED" },
|
extensions: { code: "UNAUTHENTICATED" },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
const scopes = clientScopes(payload);
|
||||||
return { userId: payload.sub, scopes };
|
return { userId: payload.sub, scopes };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,12 +81,12 @@ export async function userContext(req: FastifyRequest): Promise<AuthContext> {
|
|||||||
issuer: LOGTO_ISSUER,
|
issuer: LOGTO_ISSUER,
|
||||||
audience: LOGTO_KYC_AUDIENCE,
|
audience: LOGTO_KYC_AUDIENCE,
|
||||||
});
|
});
|
||||||
const scopes = scopesFromPayload(payload);
|
if (!payload.sub) {
|
||||||
if (!scopes.includes("teams:user")) {
|
|
||||||
throw new GraphQLError("Unauthorized", {
|
throw new GraphQLError("Unauthorized", {
|
||||||
extensions: { code: "UNAUTHENTICATED" },
|
extensions: { code: "UNAUTHENTICATED" },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
const scopes = clientScopes(payload);
|
||||||
return { userId: payload.sub, scopes };
|
return { userId: payload.sub, scopes };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user