mbkauthe 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +6 -2
- package/lib/main.js +2 -1
- package/lib/pool.js +32 -1
- package/lib/validateSessionAndRole.js +3 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2,7 +2,12 @@ import router from "./lib/main.js";
|
|
|
2
2
|
|
|
3
3
|
import dotenv from "dotenv";
|
|
4
4
|
dotenv.config();
|
|
5
|
-
|
|
5
|
+
let mbkautheVar;
|
|
6
|
+
try {
|
|
7
|
+
mbkautheVar = JSON.parse(process.env.mbkautheVar);
|
|
8
|
+
} catch (error) {
|
|
9
|
+
throw new Error("Invalid JSON in process.env.mbkautheVar");
|
|
10
|
+
}
|
|
6
11
|
if (!mbkautheVar) {
|
|
7
12
|
throw new Error("mbkautheVar is not defined");
|
|
8
13
|
}
|
|
@@ -27,7 +32,6 @@ if (mbkautheVar.BypassUsers !== undefined) {
|
|
|
27
32
|
if (!Array.isArray(mbkautheVar.BypassUsers)) {
|
|
28
33
|
throw new Error("mbkautheVar.BypassUsers must be a valid array");
|
|
29
34
|
}
|
|
30
|
-
const BypassUsers = mbkautheVar.BypassUsers;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
|
package/lib/main.js
CHANGED
|
@@ -128,7 +128,8 @@ router.post("/mbkauthe/api/login", async (req, res) => {
|
|
|
128
128
|
const secretKey = mbkautheVar.RECAPTCHA_SECRET_KEY;
|
|
129
129
|
const verificationUrl = `https://www.google.com/recaptcha/api/siteverify?secret=${secretKey}&response=${recaptcha}`;
|
|
130
130
|
|
|
131
|
-
let BypassUsers =
|
|
131
|
+
let BypassUsers = Array.isArray(mbkautheVar.BypassUsers) ? mbkautheVar.BypassUsers : JSON.parse(mbkautheVar.BypassUsers); // Ensure it's a flat array
|
|
132
|
+
|
|
132
133
|
if (mbkautheVar.RECAPTCHA_Enabled === "true") {
|
|
133
134
|
if (!BypassUsers.includes(username)) {
|
|
134
135
|
if (!recaptcha) {
|
package/lib/pool.js
CHANGED
|
@@ -3,7 +3,38 @@ const { Pool } = pkg;
|
|
|
3
3
|
|
|
4
4
|
import dotenv from "dotenv";
|
|
5
5
|
dotenv.config();
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
let mbkautheVar;
|
|
8
|
+
try {
|
|
9
|
+
mbkautheVar = JSON.parse(process.env.mbkautheVar);
|
|
10
|
+
} catch (error) {
|
|
11
|
+
throw new Error("Invalid JSON in process.env.mbkautheVar");
|
|
12
|
+
}
|
|
13
|
+
if (!mbkautheVar) {
|
|
14
|
+
throw new Error("mbkautheVar is not defined");
|
|
15
|
+
}
|
|
16
|
+
const requiredKeys = ["APP_NAME", "RECAPTCHA_Enabled", "SESSION_SECRET_KEY", "IS_DEPLOYED", "LOGIN_DB", "MBKAUTH_TWO_FA_ENABLE", "DOMAIN"];
|
|
17
|
+
requiredKeys.forEach(key => {
|
|
18
|
+
if (!mbkautheVar[key]) {
|
|
19
|
+
throw new Error(`mbkautheVar.${key} is required`);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
if (mbkautheVar.RECAPTCHA_Enabled === "true") {
|
|
23
|
+
if (mbkautheVar.RECAPTCHA_SECRET_KEY === undefined) {
|
|
24
|
+
throw new Error("mbkautheVar.RECAPTCHA_SECRET_KEY is required");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (mbkautheVar.COOKIE_EXPIRE_TIME !== undefined) {
|
|
28
|
+
const expireTime = parseFloat(mbkautheVar.COOKIE_EXPIRE_TIME);
|
|
29
|
+
if (isNaN(expireTime) || expireTime <= 0) {
|
|
30
|
+
throw new Error("mbkautheVar.COOKIE_EXPIRE_TIME must be a valid positive number");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (mbkautheVar.BypassUsers !== undefined) {
|
|
34
|
+
if (!Array.isArray(mbkautheVar.BypassUsers)) {
|
|
35
|
+
throw new Error("mbkautheVar.BypassUsers must be a valid array");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
7
38
|
|
|
8
39
|
// PostgreSQL connection pool for pool
|
|
9
40
|
const poolConfig = {
|
|
@@ -60,6 +60,9 @@ async function validateSession(req, res, next) {
|
|
|
60
60
|
if (userResult.Role !== "SuperAdmin") {
|
|
61
61
|
const allowedApps = userResult.AllowedApps;
|
|
62
62
|
if (!allowedApps || !allowedApps.includes(mbkautheVar.APP_NAME)) {
|
|
63
|
+
console.log(`Allowed Apps for user "${req.session.user.username}": ${allowedApps}`);
|
|
64
|
+
console.log(!allowedApps);
|
|
65
|
+
console.log(!allowedApps.includes(mbkautheVar.APP_NAME));
|
|
63
66
|
console.warn(`User \"${req.session.user.username}\" is not authorized to use the application \"${mbkautheVar.APP_NAME}\"`);
|
|
64
67
|
req.session.destroy();
|
|
65
68
|
res.clearCookie("mbkauthe.sid", { domain: `.${mbkautheVar.DOMAIN}` });
|