This commit is contained in:
Allan Carr
2025-07-13 00:17:08 -07:00
parent 231130267f
commit 7f782d5a64
19 changed files with 2564 additions and 1416 deletions

View File

@@ -1,23 +1,32 @@
import dotenv from "dotenv";
import { NextFunction, Request, Response } from "express";
import { resolve } from "path";
import { logger } from "../server.js";
dotenv.config({
path: resolve(process.cwd(), `.env.${process.env.NODE_ENV || "development"}`)
});
export default function ValidateImsToken(req: Request, res: Response, next: NextFunction) {
const jobid: string = (req.body.jobid || "").trim();
try {
const IMS_TOKEN: string = (process.env.IMS_TOKEN || "").trim();
const IMS_TOKEN: string = (process.env.IMS_TOKEN || "").trim();
if (IMS_TOKEN === "") {
next();
} else {
if (req.headers.ims_token !== IMS_TOKEN) {
res.sendStatus(401);
} else {
if (!IMS_TOKEN) {
logger.debug("IMS_TOKEN not set, skipping token validation.");
next();
return;
}
const token = req.headers.ims_token || req.headers["ims-token"] || req.headers["x-ims-token"];
if (token !== IMS_TOKEN) {
logger.warn("Invalid IMS token provided.", { provided: token });
res.sendStatus(401);
return;
}
next();
} catch (error) {
logger.error("Error validating IMS token.", { error: (error as Error).message });
if (!res.headersSent) res.status(500).json({ error: "Error validating IMS token." });
}
}