@plusscommunities/pluss-core-aws 2.0.21 → 2.0.22
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.
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const crypto = require("crypto");
|
|
2
|
+
const { getRef } = require("../../db/common/getRef");
|
|
3
|
+
|
|
4
|
+
module.exports = async (token) => {
|
|
5
|
+
if (!token) return false;
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
// Create hash of token for TokenId lookup
|
|
9
|
+
const tokenHash = crypto.createHash("sha256").update(token).digest("hex");
|
|
10
|
+
|
|
11
|
+
// Check if token exists in blacklist
|
|
12
|
+
const blacklistedToken = await getRef(
|
|
13
|
+
"invalidTokens",
|
|
14
|
+
"TokenId",
|
|
15
|
+
tokenHash
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
// Return true if found (blacklisted), false if not found
|
|
19
|
+
return !!blacklistedToken;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
// If error occurs during lookup, assume token is not blacklisted
|
|
22
|
+
// This ensures authentication doesn't fail due to blacklist issues
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
const https = require("https");
|
|
2
2
|
const jose = require("node-jose");
|
|
3
3
|
const { getConfig } = require("../../config");
|
|
4
|
+
const checkTokenBlacklist = require("./checkTokenBlacklist");
|
|
4
5
|
|
|
5
6
|
module.exports = async (token) => {
|
|
6
|
-
return new Promise((resolve, reject) => {
|
|
7
|
+
return new Promise(async (resolve, reject) => {
|
|
8
|
+
if (!token) {
|
|
9
|
+
return resolve(null);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Check if token is blacklisted before expensive verification
|
|
13
|
+
const isBlacklisted = await checkTokenBlacklist(token);
|
|
14
|
+
if (isBlacklisted) {
|
|
15
|
+
reject("Token has been invalidated");
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
7
19
|
var sections = token.split(".");
|
|
8
20
|
// get the kid from the headers prior to verification
|
|
9
21
|
var header = jose.util.base64url.decode(sections[0]);
|