This commit is contained in:
+7
-5
@@ -1,6 +1,6 @@
|
||||
import { createRemoteJWKSet, jwtVerify, type JWTPayload } from "jose";
|
||||
import { GraphQLError } from "graphql";
|
||||
import type { Request } from "express";
|
||||
import type { FastifyRequest } from "fastify";
|
||||
|
||||
const LOGTO_JWKS_URL =
|
||||
process.env.LOGTO_JWKS_URL || "https://auth.optovia.ru/oidc/jwks";
|
||||
@@ -16,7 +16,7 @@ export interface AuthContext {
|
||||
scopes: string[];
|
||||
}
|
||||
|
||||
function getBearerToken(req: Request): string {
|
||||
function getBearerToken(req: FastifyRequest): string {
|
||||
const auth = req.headers.authorization || "";
|
||||
if (!auth.startsWith("Bearer ")) {
|
||||
throw new GraphQLError("Missing Bearer token", {
|
||||
@@ -61,7 +61,7 @@ export async function publicContext(): Promise<AuthContext> {
|
||||
return { scopes: [] };
|
||||
}
|
||||
|
||||
export async function userContext(req: Request): Promise<AuthContext> {
|
||||
export async function userContext(req: FastifyRequest): Promise<AuthContext> {
|
||||
const token = getBearerToken(req);
|
||||
const { payload } = await jwtVerify(token, jwks, { issuer: LOGTO_ISSUER });
|
||||
return {
|
||||
@@ -70,7 +70,7 @@ export async function userContext(req: Request): Promise<AuthContext> {
|
||||
};
|
||||
}
|
||||
|
||||
export async function teamContext(req: Request): Promise<AuthContext> {
|
||||
export async function teamContext(req: FastifyRequest): Promise<AuthContext> {
|
||||
const token = getBearerToken(req);
|
||||
const { payload } = await jwtVerify(token, jwks, {
|
||||
issuer: LOGTO_ISSUER,
|
||||
@@ -95,7 +95,9 @@ export async function teamContext(req: Request): Promise<AuthContext> {
|
||||
};
|
||||
}
|
||||
|
||||
export async function managerContext(req: Request): Promise<AuthContext> {
|
||||
export async function managerContext(
|
||||
req: FastifyRequest,
|
||||
): Promise<AuthContext> {
|
||||
const token = getBearerToken(req);
|
||||
const { payload } = await jwtVerify(token, jwks, {
|
||||
issuer: LOGTO_ISSUER,
|
||||
|
||||
Reference in New Issue
Block a user