mbkauthe 1.0.19 → 1.0.21
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/README.md +35 -2
- package/index.js +9 -2
- package/lib/main.js +47 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
- [Login](#login)
|
|
22
22
|
- [Logout](#logout)
|
|
23
23
|
- [Terminate All Sessions](#terminate-all-sessions)
|
|
24
|
+
- [Package Information](#package-information)
|
|
25
|
+
- [Version Information](#version-information)
|
|
26
|
+
- [Package Lock Information](#package-lock-information)
|
|
24
27
|
- [Database Structure](#database-structure)
|
|
25
28
|
- [License](#license)
|
|
26
29
|
- [Contact \& Support](#contact--support)
|
|
@@ -211,8 +214,38 @@ router.post(["/terminateAllSessions"], authenticate(mbkautheVar.Password), (req,
|
|
|
211
214
|
- Response:
|
|
212
215
|
- `200`: All sessions terminated successfully.
|
|
213
216
|
- `500`: Internal server error.
|
|
214
|
-
|
|
215
|
-
|
|
217
|
+
|
|
218
|
+
### Package Information
|
|
219
|
+
|
|
220
|
+
**GET** `/mbkauthe/package`
|
|
221
|
+
|
|
222
|
+
- **Description**: Retrieves the `package.json` file of the `mbkauthe` package, which contains metadata about the package, such as its name, version, dependencies, and more.
|
|
223
|
+
- **Response**:
|
|
224
|
+
- `200`: Successfully retrieved the `package.json` file.
|
|
225
|
+
- **Body**: JSON object containing the contents of the `package.json` file.
|
|
226
|
+
- `500`: Internal server error.
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
### Version Information
|
|
230
|
+
|
|
231
|
+
**GET** `/mbkauthe/version` or `/mbkauthe/v`
|
|
232
|
+
|
|
233
|
+
- **Description**: Retrieves the current version of the `mbkauthe` package from the `package.json` file.
|
|
234
|
+
- **Response**:
|
|
235
|
+
- `200`: Successfully retrieved the version information.
|
|
236
|
+
- **Body**: JSON object containing the version, e.g., `{ "version": "1.0.0" }`.
|
|
237
|
+
- `500`: Internal server error.
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
### Package Lock Information
|
|
241
|
+
|
|
242
|
+
**GET** `/mbkauthe/package-lock`
|
|
243
|
+
|
|
244
|
+
- **Description**: Retrieves the `package-lock.json` file from the project where the `mbkauthe` package is installed. Filters and returns only the dependency information related to `mbkauthe`, including resolved versions and integrity hashes.
|
|
245
|
+
- **Response**:
|
|
246
|
+
- `200`: Successfully retrieved the filtered `package-lock.json` data for `mbkauthe`.
|
|
247
|
+
- **Body**: JSON object containing the filtered dependency information for `mbkauthe`.
|
|
248
|
+
- `500`: Internal server error.
|
|
216
249
|
|
|
217
250
|
## Database Structure
|
|
218
251
|
|
package/index.js
CHANGED
|
@@ -21,8 +21,7 @@ if (mbkautheVar.RECAPTCHA_Enabled === "true") {
|
|
|
21
21
|
if (mbkautheVar.RECAPTCHA_SECRET_KEY === undefined) {
|
|
22
22
|
throw new Error("mbkautheVar.RECAPTCHA_SECRET_KEY is required");
|
|
23
23
|
}
|
|
24
|
-
}
|
|
25
|
-
|
|
24
|
+
}
|
|
26
25
|
if (mbkautheVar.COOKIE_EXPIRE_TIME !== undefined) {
|
|
27
26
|
const expireTime = parseFloat(mbkautheVar.COOKIE_EXPIRE_TIME);
|
|
28
27
|
if (isNaN(expireTime) || expireTime <= 0) {
|
|
@@ -35,6 +34,14 @@ if (mbkautheVar.BypassUsers !== undefined) {
|
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
|
|
37
|
+
if (process.env.test === "true") {
|
|
38
|
+
const app = express();
|
|
39
|
+
const port = 3000;
|
|
40
|
+
app.use(router);
|
|
41
|
+
app.listen(port, () => {
|
|
42
|
+
console.log(`Server running on http://localhost:${port}`);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
38
45
|
|
|
39
46
|
export { validateSession, checkRolePermission, validateSessionAndRole, getUserData, authenticate } from "./lib/validateSessionAndRole.js";
|
|
40
47
|
export { dblogin } from "./lib/pool.js";
|
package/lib/main.js
CHANGED
|
@@ -8,6 +8,12 @@ import { authenticate } from "./validateSessionAndRole.js";
|
|
|
8
8
|
import fetch from 'node-fetch';
|
|
9
9
|
import cookieParser from "cookie-parser";
|
|
10
10
|
|
|
11
|
+
import { createRequire } from "module";
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
const packageJson = require("../package.json");
|
|
14
|
+
import fs from "fs";
|
|
15
|
+
import path from "path";
|
|
16
|
+
|
|
11
17
|
import dotenv from "dotenv";
|
|
12
18
|
dotenv.config();
|
|
13
19
|
const mbkautheVar = JSON.parse(process.env.mbkautheVar);
|
|
@@ -64,14 +70,6 @@ const sessionConfig = {
|
|
|
64
70
|
name: 'mbkauthe.sid'
|
|
65
71
|
};
|
|
66
72
|
|
|
67
|
-
router.use(async (req, res, next) => {
|
|
68
|
-
if (req.session && req.session.user) {
|
|
69
|
-
const cookieOptions = getCookieOptions();
|
|
70
|
-
res.cookie("username", req.session.user.username, { ...cookieOptions, httpOnly: false }); // Allow JavaScript access
|
|
71
|
-
res.cookie("sessionId", req.session.user.sessionId, cookieOptions); // Keep httpOnly for sensitive cookies
|
|
72
|
-
}
|
|
73
|
-
next();
|
|
74
|
-
});
|
|
75
73
|
router.use(session(sessionConfig));
|
|
76
74
|
|
|
77
75
|
// Middleware to handle session restoration from sessionId cookie
|
|
@@ -110,7 +108,7 @@ const getCookieOptions = () => ({
|
|
|
110
108
|
router.use(async (req, res, next) => {
|
|
111
109
|
if (req.session && req.session.user) {
|
|
112
110
|
const cookieOptions = getCookieOptions();
|
|
113
|
-
res.cookie("username", req.session.user.username, cookieOptions);
|
|
111
|
+
res.cookie("username", req.session.user.username, { ...cookieOptions, httpOnly: false });
|
|
114
112
|
res.cookie("sessionId", req.session.user.sessionId, cookieOptions);
|
|
115
113
|
}
|
|
116
114
|
next();
|
|
@@ -310,4 +308,44 @@ router.post("/mbkauthe/api/logout", async (req, res) => {
|
|
|
310
308
|
}
|
|
311
309
|
});
|
|
312
310
|
|
|
311
|
+
// Return package.json data of mbkauthe
|
|
312
|
+
router.get("/mbkauthe/package", (_, res) => {
|
|
313
|
+
res.status(200).json({ version: packageJson });
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// Return version number of mbkauthe
|
|
317
|
+
router.get(["/mbkauthe/version", "/mbkauthe/v"], (_, res) => {
|
|
318
|
+
res.status(200).json({ version: packageJson.version });
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// Return package-lock.json data of mbkauthe from project the package is installed in
|
|
322
|
+
router.get("/mbkauthe/package-lock", (_, res) => {
|
|
323
|
+
console.log("Request for package-lock.json received");
|
|
324
|
+
const packageLockPath = path.resolve(process.cwd(), "package-lock.json");
|
|
325
|
+
fs.readFile(packageLockPath, "utf8", (err, data) => {
|
|
326
|
+
if (err) {
|
|
327
|
+
console.error("Error reading package-lock.json:", err);
|
|
328
|
+
return res.status(500).json({ success: false, message: "Failed to read package-lock.json" });
|
|
329
|
+
}
|
|
330
|
+
try {
|
|
331
|
+
const packageLock = JSON.parse(data);
|
|
332
|
+
const mbkautheData = {
|
|
333
|
+
name: 'mbkauthe',
|
|
334
|
+
version: packageLock.packages['node_modules/mbkauthe'].version,
|
|
335
|
+
resolved: packageLock.packages['node_modules/mbkauthe'].resolved,
|
|
336
|
+
integrity: packageLock.packages['node_modules/mbkauthe'].integrity,
|
|
337
|
+
license: packageLock.packages['node_modules/mbkauthe'].license,
|
|
338
|
+
dependencies: packageLock.packages['node_modules/mbkauthe'].dependencies
|
|
339
|
+
};
|
|
340
|
+
const rootDependency = packageLock.packages[''].dependencies.mbkauthe;
|
|
341
|
+
console.log('mbkauthe package data:', mbkautheData);
|
|
342
|
+
console.log('Root dependency version:', rootDependency);
|
|
343
|
+
res.status(200).json({ mbkautheData, rootDependency });
|
|
344
|
+
} catch (parseError) {
|
|
345
|
+
console.error("Error parsing package-lock.json:", parseError);
|
|
346
|
+
res.status(500).json({ success: false, message: "Failed to parse package-lock.json" });
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
313
351
|
export default router;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mbkauthe",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
4
4
|
"description": "MBKTechStudio's reusable authentication system for Node.js applications.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "node index.js"
|
|
8
|
+
"test": "set test=true&& node index.js"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|