From 46b7aceb0b86b03688faf0ec6661e4c9fbc6115c Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Wed, 17 Mar 2021 17:40:01 +0100 Subject: [PATCH] Scanauth return objects --- src/middlewares/ScanAuth.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/middlewares/ScanAuth.ts b/src/middlewares/ScanAuth.ts index 05793f0..eefe69c 100644 --- a/src/middlewares/ScanAuth.ts +++ b/src/middlewares/ScanAuth.ts @@ -15,14 +15,14 @@ import authchecker from './authchecker'; const ScanAuth = async (req: Request, res: Response, next: () => void) => { let provided_token: string = req.headers["authorization"]; if (provided_token == "" || provided_token === undefined || provided_token === null) { - res.status(401).send("No api token provided."); + res.status(401).send({ http_code: 401, short: "no_token", message: "No api token provided." }); return; } try { provided_token = provided_token.replace("Bearer ", ""); } catch (error) { - res.status(401).send("No valid jwt or api token provided."); + res.status(401).send({ http_code: 401, short: "no_token", message: "No valid jwt or api token provided." }); return; } @@ -32,7 +32,7 @@ const ScanAuth = async (req: Request, res: Response, next: () => void) => { } finally { if (prefix == "" || prefix == undefined || prefix == null) { - res.status(401).send("Api token non-existent or invalid syntax."); + res.status(401).send({ http_code: 401, short: "invalid_token", message: "Api token non-existent or invalid syntax." }); return; } } @@ -46,7 +46,7 @@ const ScanAuth = async (req: Request, res: Response, next: () => void) => { } finally { if (user_authorized == false) { - res.status(401).send("Api token non-existent or invalid syntax."); + res.status(401).send({ http_code: 401, short: "invalid_token", message: "Api token non-existent or invalid syntax." }); return; } else { @@ -56,10 +56,10 @@ const ScanAuth = async (req: Request, res: Response, next: () => void) => { } else { if (station.enabled == false) { - res.status(401).send("Station disabled."); + res.status(401).send({ http_code: 401, short: "station_disabled", message: "Station is disabled." }); } if (!(await argon2.verify(station.key, provided_token))) { - res.status(401).send("Api token invalid."); + res.status(401).send({ http_code: 401, short: "invalid_token", message: "Api token non-existent or invalid syntax." }); return; } req.headers["station_id"] = station.id.toString();