diff --git a/routes/auth.js b/routes/auth.js index 515e74d..d99beae 100644 --- a/routes/auth.js +++ b/routes/auth.js @@ -1,4 +1,4 @@ -import { app, db, globalConfig } from "../index.js" // Get globals from index +// import { app, db, globalConfig } from "../index.js" // Get globals from index import { checkTokenNew } from "../liberals/auth.js" import { logRequest } from "../liberals/logging.js" import { randomStringBase62, getHumanReadableUserAgent } from "../liberals/misc.js" @@ -80,6 +80,7 @@ app.get("/api/auth/callback", (rreq,rres) => { let newDestination = atob(rreq.query.state.split("_")[1].replace("-","/")) rres.setHeader("Set-Cookie", `APIToken=${newToken}; Domain=${rreq.hostname}; Expires=${new Date(newExpiration).toUTCString()}; Path=/`).redirect(newDestination) } else if (rreq.query.state === "display") { + // Change this to not write the token to a cookie rres.setHeader("Set-Cookie", `APIToken=${newToken}; Domain=${rreq.hostname}; Expires=${new Date(newExpiration).toUTCString()}; Path=/`).send(`Success! Your token is ${newToken}`) } else if (rreq.query.state === "close") { rres.setHeader("Set-Cookie", `APIToken=${newToken}; Domain=${rreq.hostname}; Expires=${new Date(newExpiration).toUTCString()}; Path=/`).send(` Success! You may now close this window.`) diff --git a/website/posts/20240409-API-Documentation.html b/website/posts/20240409-API-Documentation.html index fd7f099..cee6fdf 100644 --- a/website/posts/20240409-API-Documentation.html +++ b/website/posts/20240409-API-Documentation.html @@ -106,5 +106,40 @@

Returns all request headers in JSON.

+ +
+

/api/auth/whoami

+ auth.js:6 +
GET
+
+

Returns JSON with the username of the token owner as well as what scopes the token has access to.

+ +
+ + auth.js:23 +
GET
+
+

Redirects the user to ECLS to login. The state parameter can be used to specify how the login flow will behave. The accepted "states" are:

+ + +
+

/api/auth/logout

+ auth.js:40 +
GET
+
+

Invalidates the token used to access the endpoint.

+ +
+

/api/auth/callback

+ auth.js:57 +
GET
+
+

Internal Use Only. This is the endpoint used by ECLS to finish the login flow. It will write the newly created token to the APIToken cookie as well as performing the action set by state, see login endpoint.

+ + \ No newline at end of file