propro-utils 1.4.2 → 1.4.4
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 +28 -11
package/package.json
CHANGED
package/src/server/index.js
CHANGED
|
@@ -30,6 +30,7 @@ function proproAuthMiddleware(options = {}, userSchema) {
|
|
|
30
30
|
|
|
31
31
|
return async (req, res, next) => {
|
|
32
32
|
console.log('proproAuthMiddleware');
|
|
33
|
+
let refreshToken;
|
|
33
34
|
try {
|
|
34
35
|
if (
|
|
35
36
|
!['/api/auth', '/api/callback', '/api/refreshToken'].includes(req.path)
|
|
@@ -39,28 +40,31 @@ function proproAuthMiddleware(options = {}, userSchema) {
|
|
|
39
40
|
|
|
40
41
|
console.log('req.path', req.path);
|
|
41
42
|
if (req.path === '/api/auth') {
|
|
42
|
-
const
|
|
43
|
-
const redirectUrl = `${authClientUrl}?response_type=code&appName=${appName}&client_id=${clientId}&redirect_uri=${encodeURIComponent(
|
|
44
|
-
redirectUri
|
|
45
|
-
)}`;
|
|
43
|
+
const redirectUrl = constructRedirectUrl(clientUrl, appName, clientId, redirectUri);
|
|
46
44
|
return res.status(200).json({redirectUrl});
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
if (req.path === '/api/refreshToken') {
|
|
50
48
|
console.log('refreshToken');
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
try {
|
|
50
|
+
refreshToken = req.cookies['x-refresh-token'];
|
|
51
|
+
} catch (error) {
|
|
54
52
|
console.log('No refresh token provided');
|
|
55
|
-
const
|
|
56
|
-
const redirectUrl = `${authClientUrl}?response_type=code&appName=${appName}&client_id=${clientId}&redirect_uri=${encodeURIComponent(
|
|
57
|
-
redirectUri
|
|
58
|
-
)}`;
|
|
53
|
+
const redirectUrl = constructRedirectUrl(clientUrl, appName, clientId, redirectUri);
|
|
59
54
|
console.log('redirectUrl', redirectUrl);
|
|
60
55
|
res
|
|
61
56
|
.status(401)
|
|
62
57
|
.json({redirectUrl, error: 'No refresh token provided'});
|
|
63
58
|
}
|
|
59
|
+
// console.log('getting refreshToken', refreshToken);
|
|
60
|
+
// if (!refreshToken) {
|
|
61
|
+
// console.log('No refresh token provided');
|
|
62
|
+
// const redirectUrl = constructRedirectUrl(clientUrl, appName, clientId, redirectUri);
|
|
63
|
+
// console.log('redirectUrl', redirectUrl);
|
|
64
|
+
// res
|
|
65
|
+
// .status(401)
|
|
66
|
+
// .json({redirectUrl, error: 'No refresh token provided'});
|
|
67
|
+
// }
|
|
64
68
|
|
|
65
69
|
const response = await post(
|
|
66
70
|
`${authUrl}/api/v1/auth/refreshTokens`,
|
|
@@ -159,4 +163,17 @@ function proproAuthMiddleware(options = {}, userSchema) {
|
|
|
159
163
|
};
|
|
160
164
|
}
|
|
161
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Constructs the redirect URL for a client application.
|
|
168
|
+
*
|
|
169
|
+
* @param {string} clientUrl - The URL of the client application.
|
|
170
|
+
* @param {string} appName - The name of the application.
|
|
171
|
+
* @param {string} clientId - The client ID.
|
|
172
|
+
* @param {string} redirectUri - The redirect URI.
|
|
173
|
+
* @return {string} The constructed redirect URL.
|
|
174
|
+
*/
|
|
175
|
+
function constructRedirectUrl(clientUrl, appName, clientId, redirectUri) {
|
|
176
|
+
return `${clientUrl}/signin?response_type=code&appName=${appName}&client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}`;
|
|
177
|
+
}
|
|
178
|
+
|
|
162
179
|
module.exports = proproAuthMiddleware;
|