From 698ad90d3e82a15b85ceb021ad5667109ac0bcdb Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Fri, 31 Mar 2023 15:26:15 +1100 Subject: Revert "Merge pull request #1008 from spacebarchat/dev/samuel" This reverts commit 69ea71aa9e0bd2e5a98904a66fba0ad3745707cb, reversing changes made to 8b2faf0b18336e5dff1eeff4e849bcfd96b09e88. --- src/api/middlewares/Authentication.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'src/api/middlewares/Authentication.ts') diff --git a/src/api/middlewares/Authentication.ts b/src/api/middlewares/Authentication.ts index 0aa585e5..400a16f4 100644 --- a/src/api/middlewares/Authentication.ts +++ b/src/api/middlewares/Authentication.ts @@ -18,9 +18,8 @@ import { checkToken, Config, Rights } from "@fosscord/util"; import * as Sentry from "@sentry/node"; -import { NextFunction, Request, Response, Router } from "express"; +import { NextFunction, Request, Response } from "express"; import { HTTPError } from "lambert-server"; -import { createSecretKey, KeyObject } from "crypto"; export const NO_AUTHORIZATION_ROUTES = [ // Authentication routes @@ -70,16 +69,6 @@ declare global { } } -let jwtPublicKey: KeyObject; - -// Initialize the jwt secret as a key object so it does not need to be regenerated for each request. -export function initAuthentication(api: Router) { - jwtPublicKey = createSecretKey( - Buffer.from(Config.get().security.jwtSecret), - ); - api.use(Authentication); -} - export async function Authentication( req: Request, res: Response, @@ -101,9 +90,11 @@ export async function Authentication( Sentry.setUser({ id: req.user_id }); try { + const { jwtSecret } = Config.get().security; + const { decoded, user } = await checkToken( req.headers.authorization, - jwtPublicKey, + jwtSecret, ); req.token = decoded; -- cgit 1.5.1