propro-utils 1.7.40 → 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 -11
- 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,9 +89,7 @@ class ProProAuthMiddleware {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
initializeServerAuth() {
|
|
93
|
-
console.log("INITIALIZE SERVER AUTH: Entered", this.serverAuth);
|
|
94
|
-
|
|
92
|
+
initializeServerAuth() {
|
|
95
93
|
if (!this.serverAuth) {
|
|
96
94
|
this.serverAuth = new ServerAuth(
|
|
97
95
|
this.options.serverOptions,
|
|
@@ -102,17 +100,11 @@ class ProProAuthMiddleware {
|
|
|
102
100
|
this.redisClient
|
|
103
101
|
);
|
|
104
102
|
}
|
|
105
|
-
console.log("INITIALIZE SERVER AUTH: UserSchema", this.serverAuth);
|
|
106
103
|
ServiceManager.registerService('UserSchema', this.userSchema);
|
|
107
|
-
console.log('INITIALIZE SERVER AUTH: UserStyleSchema', this.userStyleSchema);
|
|
108
104
|
ServiceManager.registerService('UserStyleSchema', this.userStyleSchema);
|
|
109
|
-
console.log('INITIALIZE SERVER AUTH: RedisClient', this.redisClient);
|
|
110
105
|
ServiceManager.registerService('RedisClient', this.redisClient);
|
|
111
|
-
console.log('INITIALIZE SERVER AUTH: FolderSchema', this.folderSchema);
|
|
112
106
|
ServiceManager.registerService('FolderSchema', this.folderSchema);
|
|
113
|
-
console.log('INITIALIZE SERVER AUTH: ThemeSchema', this.themeSchema);
|
|
114
107
|
ServiceManager.registerService('ThemeSchema', this.themeSchema);
|
|
115
|
-
console.log('INITIALIZE SERVER AUTH: Exited');
|
|
116
108
|
return this.serverAuth.middleware();
|
|
117
109
|
}
|
|
118
110
|
|
|
@@ -125,14 +117,12 @@ class ProProAuthMiddleware {
|
|
|
125
117
|
|
|
126
118
|
middleware() {
|
|
127
119
|
return (req, res, next) => {
|
|
128
|
-
console.log("MIDDLEWARE: Entered", this.options)
|
|
129
120
|
try {
|
|
130
121
|
if (this.options.useServerAuth) {
|
|
131
122
|
return this.initializeServerAuth()(req, res, next);
|
|
132
123
|
} else if (this.options.useClientAuth) {
|
|
133
124
|
return this.initializeClientAuth()(req, res, next);
|
|
134
125
|
} else {
|
|
135
|
-
console.log("MIDDLEWARE: next()")
|
|
136
126
|
next();
|
|
137
127
|
}
|
|
138
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 = {
|