From 24805d2aa08a53bb7d6fa0c45f4731950ba0267c Mon Sep 17 00:00:00 2001 From: batmanisko Date: Wed, 28 Jun 2023 19:04:40 +0200 Subject: [PATCH] cteni remote-user hlavicky z forwardauth --- server/src/index.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/server/src/index.ts b/server/src/index.ts index 99cf5c9..02db08f 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -38,19 +38,31 @@ const parseToken = (req: any) => { // ----------- Metody nevyžadující token -------------- +app.get("/api/whoami",(req,res)=>{ + res.send(req.header('remote-user')); +}) + app.post("/api/login", (req, res) => { if (!req.body?.login) { throw Error("Nebyl předán login"); } - // TODO zavést podmínky pro délku loginu (min i max) - const token = generateToken(req.body.login); - res.status(200).json(token); + // TODO: je tohle hnusny?... bude to fungovat? lol + if (req.header('remote-user')){ + let username = req.header('remote-user') || "jmenonemahlavicku" + res.status(200).json(generateToken(username)); + } else { + // TODO zavést podmínky pro délku loginu (min i max) + res.status(200).json(generateToken(req.body.login)); + } }); // ---------------------------------------------------- /** Middleware ověřující JWT token */ app.use((req, res, next) => { + if (req.header('remote-user')){ + console.log("Tvuj username: %s.", req.header('remote-user')); + } if (!req.headers.authorization) { return res.status(401).json({ error: 'Nebyl předán autentizační token' }); }