more auth changes + add tokenman page
This commit is contained in:
@@ -5,7 +5,7 @@ import { randomStringBase62, getHumanReadableUserAgent } from "../liberals/misc.
|
||||
|
||||
app.get("/api/auth/whoami", (rreq,rres) => {
|
||||
if (!rreq.cookies["APIToken"] && !rreq.get("Authorization")) {
|
||||
rres.send({ "loggedIn": false, "username": "", "scopes": "" })
|
||||
rres.status(400).send({ "loggedIn": false, "username": "", "scopes": "" })
|
||||
} else {
|
||||
db`select s.scopes, u.username from sessions s join users u on s.owner = u.id where s.token = ${rreq.cookies["APIToken"] ?? rreq.get("Authorization")}`.then(dbRes => {
|
||||
if (dbRes.length > 0 && dbRes.length < 2) {
|
||||
@@ -37,6 +37,23 @@ app.get("/api/auth/login", (rreq,rres) => {
|
||||
|
||||
})
|
||||
|
||||
app.get("/api/auth/logout", (rreq,rres) => {
|
||||
if (rreq.cookies["APIToken"] || rreq.get("Authorization")) {
|
||||
db`delete from sessions where token = ${rreq.cookies["APIToken"] ?? rreq.get("Authorization")}`.then(dbRes => {
|
||||
if (dbRes.count > 0) {
|
||||
rres.send("Success")
|
||||
} else {
|
||||
rres.status(400).send("Error: Token does not exist.")
|
||||
}
|
||||
}).catch(dbErr => {
|
||||
logRequest(rres,rreq,500,dbErr)
|
||||
rres.status(500).send("Error: Exception occured while invalidating token, details: "+dbErr)
|
||||
})
|
||||
} else {
|
||||
rres.status(400).send("Error: Missing token or authorization header, you may not be logged in.")
|
||||
}
|
||||
})
|
||||
|
||||
app.get("/api/auth/callback", (rreq,rres) => {
|
||||
fetch(globalConfig.oidc.tokenUrl, { // Call token endpoint at IdP using code provdided during callback
|
||||
method: "POST",
|
||||
@@ -99,4 +116,12 @@ app.delete("/api/auth/token", (rreq,rres) => {
|
||||
rres.send("Non functional endpoint")
|
||||
})
|
||||
|
||||
app.get("/api/auth/tokenlist", (rreq,rres) => {
|
||||
rres.send("Non functional endpoint")
|
||||
})
|
||||
|
||||
app.get("/api/auth/nuke", (rreq,rres) => {
|
||||
rres.send("Non functional endpoint")
|
||||
})
|
||||
|
||||
export { app }
|
||||
@@ -39,10 +39,6 @@ app.get("/posts/*", (rreq,rres) => {
|
||||
|
||||
})
|
||||
|
||||
app.get("/urltoolbox", (rreq,rres) => {
|
||||
rres.send("Under construction")
|
||||
})
|
||||
|
||||
function parseFiles() {
|
||||
let files = fs.readdirSync(process.cwd()+"/website/posts")
|
||||
let result = ""
|
||||
|
||||
Reference in New Issue
Block a user