auth modification
This commit is contained in:
@@ -25,16 +25,17 @@ async function checkToken(token,scope) {
|
|||||||
* @typedef {Object} Object containing the result and the username of the token owner
|
* @typedef {Object} Object containing the result and the username of the token owner
|
||||||
* @property {boolean} result Boolean result of if the check passed
|
* @property {boolean} result Boolean result of if the check passed
|
||||||
* @property {string} owner Username of the token owner
|
* @property {string} owner Username of the token owner
|
||||||
|
* @property {number} ownerId Database ID of the token owner
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async function checkTokenNew(token,scope) {
|
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) {
|
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)) {
|
} 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 {
|
} else {
|
||||||
return { result: false, owner: response[0]?.username}
|
return { result: false, owner: response[0]?.username, ownerId: response[0]?.owner}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
25
routes/auth.js
Normal file
25
routes/auth.js
Normal file
@@ -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 }
|
||||||
Reference in New Issue
Block a user