propro-utils 1.4.5 → 1.4.7
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/package.json +1 -1
- package/src/server/index.js +8 -18
package/package.json
CHANGED
package/src/server/index.js
CHANGED
|
@@ -28,9 +28,9 @@ function proproAuthMiddleware(options = {}, userSchema) {
|
|
|
28
28
|
appName = process.env.APP_NAME,
|
|
29
29
|
} = options;
|
|
30
30
|
|
|
31
|
+
let refreshToken;
|
|
32
|
+
|
|
31
33
|
return async (req, res, next) => {
|
|
32
|
-
console.log('proproAuthMiddleware');
|
|
33
|
-
let refreshToken;
|
|
34
34
|
try {
|
|
35
35
|
if (
|
|
36
36
|
!['/api/auth', '/api/callback', '/api/refreshToken'].includes(req.path)
|
|
@@ -45,27 +45,16 @@ function proproAuthMiddleware(options = {}, userSchema) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
if (req.path === '/api/refreshToken') {
|
|
48
|
-
|
|
49
|
-
console.log('req.cookies', req.cookies);
|
|
50
|
-
try {
|
|
48
|
+
if (req.cookies) {
|
|
51
49
|
refreshToken = req.cookies['x-refresh-token'];
|
|
52
|
-
}
|
|
53
|
-
|
|
50
|
+
}
|
|
51
|
+
// const refreshToken = req.cookies['x-refresh-token'];
|
|
52
|
+
if (!refreshToken) {
|
|
54
53
|
const redirectUrl = constructRedirectUrl(clientUrl, appName, clientId, redirectUri);
|
|
55
|
-
|
|
56
|
-
res
|
|
54
|
+
return res
|
|
57
55
|
.status(401)
|
|
58
56
|
.json({redirectUrl, error: 'No refresh token provided'});
|
|
59
57
|
}
|
|
60
|
-
// console.log('getting refreshToken', refreshToken);
|
|
61
|
-
// if (!refreshToken) {
|
|
62
|
-
// console.log('No refresh token provided');
|
|
63
|
-
// const redirectUrl = constructRedirectUrl(clientUrl, appName, clientId, redirectUri);
|
|
64
|
-
// console.log('redirectUrl', redirectUrl);
|
|
65
|
-
// res
|
|
66
|
-
// .status(401)
|
|
67
|
-
// .json({redirectUrl, error: 'No refresh token provided'});
|
|
68
|
-
// }
|
|
69
58
|
|
|
70
59
|
const response = await post(
|
|
71
60
|
`${authUrl}/api/v1/auth/refreshTokens`,
|
|
@@ -174,6 +163,7 @@ function proproAuthMiddleware(options = {}, userSchema) {
|
|
|
174
163
|
* @return {string} The constructed redirect URL.
|
|
175
164
|
*/
|
|
176
165
|
function constructRedirectUrl(clientUrl, appName, clientId, redirectUri) {
|
|
166
|
+
console.log('constructRedirectUrl', clientUrl, appName, clientId, redirectUri);
|
|
177
167
|
return `${clientUrl}/signin?response_type=code&appName=${appName}&client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}`;
|
|
178
168
|
}
|
|
179
169
|
|