From 9f96d82e53d34ba191b68c312848455f5c0332d8 Mon Sep 17 00:00:00 2001 From: Enstrayed <48845980+Enstrayed@users.noreply.github.com> Date: Fri, 18 Apr 2025 22:36:15 -0700 Subject: [PATCH] auth modification --- liberals/auth.js | 9 +++++---- routes/auth.js | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 routes/auth.js diff --git a/liberals/auth.js b/liberals/auth.js index 6348230..0db2b29 100644 --- a/liberals/auth.js +++ b/liberals/auth.js @@ -25,16 +25,17 @@ async function checkToken(token,scope) { * @typedef {Object} Object containing the result and the username of the token owner * @property {boolean} result Boolean result of if the check passed * @property {string} owner Username of the token owner + * @property {number} ownerId Database ID of the token owner */ async function checkTokenNew(token,scope) { - return await db`select s.token, s.scopes, s.expires, u.username from sessions s join users u on s.owner = u.id where s.token = ${token}`.then(response => { + return await db`select s.*, u.username from sessions s join users u on s.owner = u.id where s.token = ${token}`.then(response => { if (response.length === 0) { - return { result: false, owner: response[0]?.username} + return { result: false, owner: response[0]?.username, ownerId: response[0]?.owner} } else if (response[0]?.scopes.split(",").includes(scope)) { - return { result: true, owner: response[0]?.username} + return { result: true, owner: response[0]?.username, ownerId: response[0]?.owner} } else { - return { result: false, owner: response[0]?.username} + return { result: false, owner: response[0]?.username, ownerId: response[0]?.owner} } }) } diff --git a/routes/auth.js b/routes/auth.js new file mode 100644 index 0000000..fce1deb --- /dev/null +++ b/routes/auth.js @@ -0,0 +1,25 @@ +import { app, db, globalConfig } from "../index.js" // Get globals from index +import { checkTokenNew } from "../liberals/auth.js" +import { logRequest } from "../liberals/logging.js" + +app.get("/api/auth/whoami", (rreq,rres) => { + rres.send("Non functional endpoint") +}) + +app.get("/api/auth/login", (rreq,rres) => { + rres.send("Non functional endpoint") +}) + +app.get("/api/auth/callback", (rreq,rres) => { + rres.send("Non functional endpoint") +}) + +app.post("/api/auth/token", (rreq,rres) => { + rres.send("Non functional endpoint") +}) + +app.delete("/api/auth/token", (rreq,rres) => { + rres.send("Non functional endpoint") +}) + +export { app } \ No newline at end of file