Return GraphQL auth errors for manager requests
Build and deploy Docker image / build (push) Successful in 2m14s
Build and deploy Docker image / build (push) Successful in 2m14s
This commit is contained in:
+10
-1
@@ -32,6 +32,14 @@ function getBearerToken(req: FastifyRequest): string {
|
||||
return token;
|
||||
}
|
||||
|
||||
function optionalBearerToken(req: FastifyRequest): string | null {
|
||||
const auth = req.headers.authorization || "";
|
||||
if (!auth.startsWith("Bearer ")) return null;
|
||||
const token = auth.slice(7);
|
||||
if (!token || token === "undefined") return null;
|
||||
return token;
|
||||
}
|
||||
|
||||
function scopesFromPayload(payload: JWTPayload): string[] {
|
||||
const scope = payload.scope;
|
||||
if (!scope) return [];
|
||||
@@ -98,7 +106,8 @@ export async function teamContext(req: FastifyRequest): Promise<AuthContext> {
|
||||
export async function managerContext(
|
||||
req: FastifyRequest,
|
||||
): Promise<AuthContext> {
|
||||
const token = getBearerToken(req);
|
||||
const token = optionalBearerToken(req);
|
||||
if (token === null) return { scopes: [] };
|
||||
const { payload } = await jwtVerify(token, jwks, {
|
||||
issuer: LOGTO_ISSUER,
|
||||
audience: LOGTO_ORDERS_AUDIENCE,
|
||||
|
||||
Reference in New Issue
Block a user