propro-utils 1.3.25 → 1.3.27
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.
|
@@ -11,14 +11,15 @@ const authValidation = (redisClient, requiredPermissions = []) => {
|
|
|
11
11
|
return res.status(403).json({ error: "Access token is required" });
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const fetchPermission = async () => {
|
|
15
|
+
const response = await axios.post(`${process.env.AUTH_URL}/api/v1/auth/validateToken`, {
|
|
16
16
|
accessToken: accessToken,
|
|
17
17
|
requiredPermissions: requiredPermissions
|
|
18
18
|
});
|
|
19
|
-
|
|
19
|
+
return response.data;
|
|
20
|
+
}
|
|
20
21
|
|
|
21
|
-
const { accountId, validPermissions }
|
|
22
|
+
const { accountId, validPermissions } = await getOrSetCache(redisClient, accessToken, fetchPermission, 1800);
|
|
22
23
|
|
|
23
24
|
if (!validPermissions) {
|
|
24
25
|
return res.status(403).json({ error: "Invalid permissions" });
|
package/package.json
CHANGED
package/src/server/index.js
CHANGED
|
@@ -49,7 +49,7 @@ function proproAuthMiddleware(options = {}) {
|
|
|
49
49
|
|
|
50
50
|
console.log("code", code);
|
|
51
51
|
|
|
52
|
-
const
|
|
52
|
+
const {tokens, redirectUrl} = await exchangeToken(
|
|
53
53
|
authUrl,
|
|
54
54
|
code,
|
|
55
55
|
clientId,
|
|
@@ -59,25 +59,25 @@ function proproAuthMiddleware(options = {}) {
|
|
|
59
59
|
|
|
60
60
|
const currentDateTime = new Date();
|
|
61
61
|
|
|
62
|
-
const refreshMaxAge =
|
|
62
|
+
const refreshMaxAge = new Date(tokens.refresh.expires).getTime() - currentDateTime.getTime();
|
|
63
63
|
|
|
64
|
-
res.cookie("x-refresh-token",
|
|
64
|
+
res.cookie("x-refresh-token", tokens.refresh.token, {
|
|
65
65
|
httpOnly: true,
|
|
66
66
|
secure: process.env.NODE_ENV === "production",
|
|
67
67
|
maxAge: refreshMaxAge
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
const accessMaxAge =
|
|
70
|
+
const accessMaxAge = new Date(tokens.access.expires).getTime() - currentDateTime.getTime();
|
|
71
71
|
|
|
72
|
-
res.cookie("x-access-token",
|
|
72
|
+
res.cookie("x-access-token", tokens.access.token, {
|
|
73
73
|
httpOnly: true,
|
|
74
74
|
secure: process.env.NODE_ENV === "production",
|
|
75
75
|
maxAge: accessMaxAge
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
const
|
|
78
|
+
const urlToRedirect = `http://${redirectUrl}/`;
|
|
79
79
|
|
|
80
|
-
return res.redirect(
|
|
80
|
+
return res.redirect(urlToRedirect);
|
|
81
81
|
}
|
|
82
82
|
} catch (error) {
|
|
83
83
|
console.error("Error in proproAuthMiddleware:", error);
|