working changes for new auth

This commit is contained in:
Enstrayed
2024-06-23 12:54:57 -07:00
parent 3b61566024
commit 8e769996e1
7 changed files with 121 additions and 75 deletions

View File

@@ -1,5 +1,5 @@
const { app, globalConfig } = require("../index.js") // Get globals from index
const { checkAuthorization } = require("../liberals/authorization.js")
const { checkToken } = require("../liberals/auth.js")
app.get("/etyd*", (rreq,rres) => {
fetch(`http://${globalConfig.couchdb.host}/etyd${rreq.path.replace("/etyd","")}`, {
@@ -30,9 +30,8 @@ app.delete("/etyd*", (rreq,rres) => {
if (rreq.get("Authorization") === undefined) {
rres.sendStatus(400)
} else {
checkAuthorization(globalConfig.etyd.authKeysDoc,rreq.get("Authorization")).then(authRes => {
checkToken(rreq.get("Authorization"),"etyd").then(authRes => {
if (authRes === false) {
console.log(`${rreq.get("cf-connecting-ip")} DELETE ${rreq.path} returned 401`) // Log unauthorized requests
rres.sendStatus(401)
} else if (authRes === true) { // Authorization successful
@@ -82,14 +81,12 @@ app.post("/etyd*", (rreq,rres) => {
if (rreq.get("Authorization") === undefined) {
rres.sendStatus(400)
} else {
checkAuthorization(globalConfig.etyd.authKeysDoc,rreq.get("Authorization")).then(authRes => {
checkToken(rreq.get("Authorization"),"etyd").then(authRes => {
if (authRes === false) {
console.log(`${rreq.get("cf-connecting-ip")} POST ${rreq.path} returned 401`) // Log unauthorized requests
rres.sendStatus(401)
} else if (authRes === true) { // Authorization successful
if (rreq.body["url"] == undefined) {
console.log(`${rreq.get("cf-connecting-ip")} POST ${rreq.path} returned 400 KEY: ${rreq.get("Authorization")}`)
rres.sendStatus(400)
} else {
fetch(`http://${globalConfig.couchdb.host}/etyd${rreq.path.replace("/etyd", "")}`, {
@@ -106,12 +103,10 @@ app.post("/etyd*", (rreq,rres) => {
switch(dbRes.status) {
case 409:
console.log(`${rreq.get("cf-connecting-ip")} POST ${rreq.path} returned 409 KEY: ${rreq.get("Authorization")}`)
rres.sendStatus(409)
break;
case 201:
console.log(`${rreq.get("cf-connecting-ip")} POST ${rreq.path} returned 200 KEY: ${rreq.get("Authorization")}`)
rres.status(200).send(rreq.path.replace("/etyd", ""))
break;
@@ -132,5 +127,4 @@ app.post("/etyd*", (rreq,rres) => {
})
module.exports = {app} // export routes to be imported by index for execution

View File

@@ -1,9 +1,9 @@
const { app, globalConfig } = require("../index.js") // Get globals from index
const { checkAuthorization } = require("../liberals/authorization.js")
const { checkToken } = require("../liberals/auth.js")
app.post("/sendemail", (rreq,rres) => {
checkAuthorization(globalConfig.mailjet.authKeysDoc,rreq.get("Authorization")).then(authRes => {
checkToken(rreq.get("Authorization"),"mailjet").then(authRes => {
if (authRes === false) { // If the supplied authorization is invalid or an error occured
console.log(`${rreq.get("cf-connecting-ip")} POST /sendemail returned 401`) // Log the request
@@ -21,8 +21,7 @@ app.post("/sendemail", (rreq,rres) => {
"Messages": [
{
"From": {
"Email": globalConfig.mailjet.senderAddress,
"Name": globalConfig.mailjet.senderName,
"Email": globalConfig.mailjet.senderAddress
},
"To": [
{