Scanauth return objects

This commit is contained in:
Nicolai Ort 2021-03-17 17:40:01 +01:00
parent 486e450a58
commit 46b7aceb0b
1 changed files with 6 additions and 6 deletions

View File

@ -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();