propro-utils 1.7.39 → 1.7.41
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/middlewares/access_token.js +22 -8
- package/package.json +1 -1
- package/src/index.js +1 -4
- package/src/server/middleware/cookieUtils.js +13 -13
|
@@ -37,15 +37,18 @@ const ServiceManager = require('../utils/serviceManager');
|
|
|
37
37
|
const authValidation = (requiredPermissions = []) => {
|
|
38
38
|
return async (req, res, next) => {
|
|
39
39
|
try {
|
|
40
|
+
console.log("AUTH VALIDATION: 1", req.cookies);
|
|
40
41
|
const accessToken =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
req.cookies?.['x-access-token'] ||
|
|
43
|
+
req.headers.authorization?.split(' ')[1];
|
|
44
|
+
|
|
45
|
+
console.log("AUTH VALIDATION: 2", accessToken);
|
|
44
46
|
if (!accessToken) {
|
|
45
47
|
return res.status(403).json({ error: 'Access token is required' });
|
|
46
48
|
}
|
|
47
|
-
|
|
49
|
+
|
|
48
50
|
const fetchPermission = async () => {
|
|
51
|
+
console.log("AUTH VALIDATION: fetchPermission()");
|
|
49
52
|
const response = await axios.post(
|
|
50
53
|
`${process.env.AUTH_URL}/api/v1/auth/validateToken`,
|
|
51
54
|
{
|
|
@@ -55,32 +58,43 @@ const authValidation = (requiredPermissions = []) => {
|
|
|
55
58
|
);
|
|
56
59
|
return response.data;
|
|
57
60
|
};
|
|
61
|
+
console.log("AUTH VALIDATION: 3");
|
|
58
62
|
const redisClient = await ServiceManager.getService('RedisClient');
|
|
63
|
+
console.log("AUTH VALIDATION: 4");
|
|
59
64
|
const cacheKey = `account:permissions:${accessToken}`;
|
|
65
|
+
console.log("AUTH VALIDATION: 5");
|
|
60
66
|
const { accountId, validPermissions } = await getOrSetCache(
|
|
61
67
|
redisClient,
|
|
62
68
|
cacheKey,
|
|
63
69
|
fetchPermission,
|
|
64
70
|
1800
|
|
65
71
|
);
|
|
66
|
-
|
|
72
|
+
console.log("AUTH VALIDATION: 6", validPermissions);
|
|
73
|
+
|
|
67
74
|
if (!validPermissions) {
|
|
68
75
|
return res.status(403).json({ error: 'Invalid permissions' });
|
|
69
76
|
}
|
|
70
|
-
|
|
77
|
+
|
|
78
|
+
console.log("AUTH VALIDATION: 7", req.account);
|
|
79
|
+
|
|
71
80
|
req.account = accountId;
|
|
72
|
-
|
|
81
|
+
|
|
73
82
|
let user = null;
|
|
74
83
|
try {
|
|
84
|
+
console.log("AUTH VALIDATION: 8");
|
|
75
85
|
user = await checkIfUserExists(accountId);
|
|
86
|
+
console.log("AUTH VALIDATION: 9", user);
|
|
76
87
|
if (!user) throw new Error('User not found');
|
|
77
88
|
} catch (error) {
|
|
89
|
+
console.log("AUTH VALIDATION: ERROR 1", error);
|
|
78
90
|
return res.status(403).json({error: error?.message || 'User not found'});
|
|
79
91
|
}
|
|
80
|
-
|
|
92
|
+
|
|
81
93
|
req.user = user.id;
|
|
94
|
+
console.log("AUTH VALIDATION: 10", req.user);
|
|
82
95
|
next();
|
|
83
96
|
} catch (error) {
|
|
97
|
+
console.log("AUTH VALIDATION: ERROR 2", error);
|
|
84
98
|
if (error.response && error.response.status) {
|
|
85
99
|
next(new Error(error.response.data.message));
|
|
86
100
|
}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -89,7 +89,7 @@ class ProProAuthMiddleware {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
initializeServerAuth() {
|
|
92
|
+
initializeServerAuth() {
|
|
93
93
|
if (!this.serverAuth) {
|
|
94
94
|
this.serverAuth = new ServerAuth(
|
|
95
95
|
this.options.serverOptions,
|
|
@@ -100,7 +100,6 @@ class ProProAuthMiddleware {
|
|
|
100
100
|
this.redisClient
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
|
-
|
|
104
103
|
ServiceManager.registerService('UserSchema', this.userSchema);
|
|
105
104
|
ServiceManager.registerService('UserStyleSchema', this.userStyleSchema);
|
|
106
105
|
ServiceManager.registerService('RedisClient', this.redisClient);
|
|
@@ -118,14 +117,12 @@ class ProProAuthMiddleware {
|
|
|
118
117
|
|
|
119
118
|
middleware() {
|
|
120
119
|
return (req, res, next) => {
|
|
121
|
-
console.log("MIDDLEWARE: Entered", this.options)
|
|
122
120
|
try {
|
|
123
121
|
if (this.options.useServerAuth) {
|
|
124
122
|
return this.initializeServerAuth()(req, res, next);
|
|
125
123
|
} else if (this.options.useClientAuth) {
|
|
126
124
|
return this.initializeClientAuth()(req, res, next);
|
|
127
125
|
} else {
|
|
128
|
-
console.log("MIDDLEWARE: next()")
|
|
129
126
|
next();
|
|
130
127
|
}
|
|
131
128
|
} catch (error) {
|
|
@@ -184,14 +184,14 @@ const setAuthCookies = async (res, tokens, account, user, appUrl) => {
|
|
|
184
184
|
|
|
185
185
|
await Promise.allSettled(extensionCookiePromises);
|
|
186
186
|
|
|
187
|
-
console.log('Auth cookies set successfully', {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
});
|
|
187
|
+
// console.log('Auth cookies set successfully', {
|
|
188
|
+
// domain,
|
|
189
|
+
// sameSite: commonAttributes.sameSite,
|
|
190
|
+
// cookieNames: [
|
|
191
|
+
// ...Object.keys(httpOnlyCookies),
|
|
192
|
+
// ...Object.keys(regularCookies),
|
|
193
|
+
// ],
|
|
194
|
+
// });
|
|
195
195
|
} catch (error) {
|
|
196
196
|
console.error('Error setting cookies:', {
|
|
197
197
|
error: error.message,
|
|
@@ -258,11 +258,11 @@ const clearAuthCookies = async (res, appUrl) => {
|
|
|
258
258
|
// Not in extension context, ignore
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
console.log('Auth cookies cleared successfully', {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
});
|
|
261
|
+
// console.log('Auth cookies cleared successfully', {
|
|
262
|
+
// domain,
|
|
263
|
+
// cookieNames,
|
|
264
|
+
// sameSite: commonAttributes.sameSite,
|
|
265
|
+
// });
|
|
266
266
|
};
|
|
267
267
|
|
|
268
268
|
module.exports = {
|