@riocrypto/common-server 1.0.2758 → 1.0.2760
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/build/middlewares/authorize.js +49 -42
- package/package.json +2 -2
|
@@ -74,58 +74,63 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
74
74
|
}))());
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
// Check for admin
|
|
78
|
-
if (authorizationTypes.includes(common_1.AuthorizationType.
|
|
77
|
+
// Check for admin API key - only if needed
|
|
78
|
+
if (authorizationTypes.includes(common_1.AuthorizationType.AdminAPIKey)) {
|
|
79
79
|
const adminApiKey = req.header("x-admin-api-key");
|
|
80
|
-
|
|
81
|
-
if (adminApiKey || adminAccessToken) {
|
|
80
|
+
if (adminApiKey) {
|
|
82
81
|
promises.push((() => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
-
var _d
|
|
82
|
+
var _d;
|
|
84
83
|
const AdminAuth = yield (0, admin_auth_1.buildAdminAuth)(mongoose);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
req.adminAuth = adminAuth;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
catch (err) {
|
|
96
|
-
(_d = logger_1.default.getLogger()) === null || _d === void 0 ? void 0 : _d.warn("Admin API key verification failed", {
|
|
97
|
-
ip: req.headers["cf-connecting-ip"] || req.ip,
|
|
98
|
-
});
|
|
84
|
+
try {
|
|
85
|
+
const hashedAdminApiKey = yield apiKey_1.ApiKey.toHash(adminApiKey);
|
|
86
|
+
const adminAuth = yield AdminAuth.findOne({
|
|
87
|
+
"apiKeys.value": hashedAdminApiKey,
|
|
88
|
+
});
|
|
89
|
+
if (adminAuth) {
|
|
90
|
+
req.adminAuth = adminAuth;
|
|
99
91
|
}
|
|
100
92
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
93
|
+
catch (err) {
|
|
94
|
+
(_d = logger_1.default.getLogger()) === null || _d === void 0 ? void 0 : _d.warn("Admin API key verification failed", {
|
|
95
|
+
ip: req.headers["cf-connecting-ip"] || req.ip,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}))());
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Check for admin auth token - only if needed
|
|
102
|
+
if (authorizationTypes.includes(common_1.AuthorizationType.AdminAuth)) {
|
|
103
|
+
const adminAccessToken = (_a = req.cookies) === null || _a === void 0 ? void 0 : _a.adminAccessToken;
|
|
104
|
+
if (adminAccessToken) {
|
|
105
|
+
promises.push((() => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
+
var _e;
|
|
107
|
+
const AdminAuth = yield (0, admin_auth_1.buildAdminAuth)(mongoose);
|
|
108
|
+
try {
|
|
109
|
+
const ADMIN_ACCESS_TOKEN_SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue("ADMIN_ACCESS_TOKEN_SECRET");
|
|
110
|
+
if (!ADMIN_ACCESS_TOKEN_SECRET) {
|
|
111
|
+
throw new Error("Unable to get ADMIN_ACCESS_TOKEN_SECRET");
|
|
112
|
+
}
|
|
113
|
+
const payload = jsonwebtoken_1.default.verify(adminAccessToken, ADMIN_ACCESS_TOKEN_SECRET);
|
|
114
|
+
const adminAuth = yield AdminAuth.findById(payload.id);
|
|
115
|
+
if (adminAuth) {
|
|
116
|
+
// Check if token version matches (for server-side invalidation)
|
|
117
|
+
if (payload.tokenVersion !== undefined &&
|
|
118
|
+
adminAuth.tokenVersion !== undefined) {
|
|
119
|
+
if (payload.tokenVersion === adminAuth.tokenVersion) {
|
|
119
120
|
req.adminAuth = adminAuth;
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
});
|
|
123
|
+
else {
|
|
124
|
+
// Backward compatibility for tokens without version
|
|
125
|
+
req.adminAuth = adminAuth;
|
|
126
|
+
}
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
(_e = logger_1.default.getLogger()) === null || _e === void 0 ? void 0 : _e.warn("Admin JWT verification failed", {
|
|
131
|
+
ip: req.headers["cf-connecting-ip"] || req.ip,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
129
134
|
}))());
|
|
130
135
|
}
|
|
131
136
|
}
|
|
@@ -290,6 +295,8 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
290
295
|
req.isAuthMissing2FA) ||
|
|
291
296
|
(authorizationTypes.includes(common_1.AuthorizationType.AdminAuth) &&
|
|
292
297
|
req.adminAuth) ||
|
|
298
|
+
(authorizationTypes.includes(common_1.AuthorizationType.AdminAPIKey) &&
|
|
299
|
+
req.adminAuth) ||
|
|
293
300
|
((authorizationTypes.includes(common_1.AuthorizationType.User) ||
|
|
294
301
|
authorizationTypes.includes(common_1.AuthorizationType.UserNoKYC)) &&
|
|
295
302
|
req.user) ||
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2760",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@google-cloud/secret-manager": "^5.6.0",
|
|
25
25
|
"@google-cloud/storage": "^7.19.0",
|
|
26
26
|
"@hyperdx/node-opentelemetry": "^0.10.3",
|
|
27
|
-
"@riocrypto/common": "^1.0.
|
|
27
|
+
"@riocrypto/common": "^1.0.2554",
|
|
28
28
|
"@slack/web-api": "^7.15.0",
|
|
29
29
|
"@types/express": "^4.17.25",
|
|
30
30
|
"axios": "1.13.6",
|