propro-utils 1.4.20 → 1.4.22
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
CHANGED
package/src/server/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require('dotenv').config();
|
|
2
|
-
const {exchangeToken} = require('./middleware/verifyToken');
|
|
2
|
+
const {exchangeToken, formatRedirectUrl} = require('./middleware/verifyToken');
|
|
3
3
|
const {checkIfUserExists} = require('../../middlewares/account_info');
|
|
4
4
|
const {post} = require('axios');
|
|
5
5
|
|
|
@@ -107,7 +107,6 @@ function proproAuthMiddleware(options = {}, userSchema) {
|
|
|
107
107
|
return res.status(400).send('No code received');
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
console.log('code', code);
|
|
111
110
|
const {tokens, account, redirectUrl} = await exchangeToken(
|
|
112
111
|
authUrl,
|
|
113
112
|
code,
|
|
@@ -116,9 +115,7 @@ function proproAuthMiddleware(options = {}, userSchema) {
|
|
|
116
115
|
redirectUri
|
|
117
116
|
);
|
|
118
117
|
|
|
119
|
-
console.log('tokens', tokens);
|
|
120
118
|
const user = await checkIfUserExists(userSchema, account.accountId);
|
|
121
|
-
console.log('user', user);
|
|
122
119
|
|
|
123
120
|
const currentDateTime = new Date();
|
|
124
121
|
|
|
@@ -149,11 +146,9 @@ function proproAuthMiddleware(options = {}, userSchema) {
|
|
|
149
146
|
|
|
150
147
|
res.cookie('account', JSON.stringify(account));
|
|
151
148
|
|
|
152
|
-
console.log('redirectUrl', redirectUrl);
|
|
153
149
|
|
|
154
|
-
const urlToRedirect = formatRedirectUrl(
|
|
150
|
+
const urlToRedirect = formatRedirectUrl(redirectUrl);
|
|
155
151
|
|
|
156
|
-
console.log('urlToRedirect', urlToRedirect);
|
|
157
152
|
|
|
158
153
|
return res.redirect(urlToRedirect);
|
|
159
154
|
}
|
|
@@ -181,27 +176,5 @@ function constructRedirectUrl(clientUrl, appName, clientId, redirectUri) {
|
|
|
181
176
|
return `${urlToRedirect}/signin?response_type=code&appName=${appName}&client_id=${clientId}&redirect_uri=${encodeURIComponent(redirectUri)}`;
|
|
182
177
|
}
|
|
183
178
|
|
|
184
|
-
/**
|
|
185
|
-
* Formats the redirect URL by adding 'http://' or 'https://' if necessary.
|
|
186
|
-
*
|
|
187
|
-
* @param {string} redirectUrl - The URL to be redirected.
|
|
188
|
-
* @return {string} The formatted redirect URL.
|
|
189
|
-
*/
|
|
190
|
-
function formatRedirectUrl(redirectUrl) {
|
|
191
|
-
let urlToRedirect;
|
|
192
|
-
|
|
193
|
-
if (!redirectUrl.startsWith('http://') && !redirectUrl.startsWith('https://')) {
|
|
194
|
-
if (redirectUrl.includes('localhost')) {
|
|
195
|
-
urlToRedirect = `http://${redirectUrl}`;
|
|
196
|
-
} else {
|
|
197
|
-
urlToRedirect = `https://${redirectUrl}`;
|
|
198
|
-
}
|
|
199
|
-
} else {
|
|
200
|
-
urlToRedirect = redirectUrl;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return urlToRedirect;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
179
|
|
|
207
180
|
module.exports = proproAuthMiddleware;
|
|
@@ -49,8 +49,9 @@ async function exchangeToken(
|
|
|
49
49
|
redirectUri
|
|
50
50
|
) {
|
|
51
51
|
try {
|
|
52
|
+
const formattedRedirectUri = formatRedirectUrl(authUrl)
|
|
52
53
|
const response = await axios.post(
|
|
53
|
-
|
|
54
|
+
formattedRedirectUri + "/api/v1/auth/authorize",
|
|
54
55
|
{
|
|
55
56
|
grantType: "authorization_code",
|
|
56
57
|
code: code,
|
|
@@ -133,8 +134,31 @@ function isValid(decodedToken, requiredPermissions) {
|
|
|
133
134
|
);
|
|
134
135
|
}
|
|
135
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Formats the redirect URL by adding 'http://' or 'https://' if necessary.
|
|
139
|
+
*
|
|
140
|
+
* @param {string} redirectUrl - The URL to be redirected.
|
|
141
|
+
* @return {string} The formatted redirect URL.
|
|
142
|
+
*/
|
|
143
|
+
function formatRedirectUrl(redirectUrl) {
|
|
144
|
+
let urlToRedirect;
|
|
145
|
+
|
|
146
|
+
if (!redirectUrl.startsWith('http://') && !redirectUrl.startsWith('https://')) {
|
|
147
|
+
if (redirectUrl.includes('localhost')) {
|
|
148
|
+
urlToRedirect = `http://${redirectUrl}`;
|
|
149
|
+
} else {
|
|
150
|
+
urlToRedirect = `https://${redirectUrl}`;
|
|
151
|
+
}
|
|
152
|
+
} else {
|
|
153
|
+
urlToRedirect = redirectUrl;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return urlToRedirect;
|
|
157
|
+
}
|
|
158
|
+
|
|
136
159
|
module.exports = {
|
|
137
160
|
VerifyAccount,
|
|
138
161
|
exchangeToken,
|
|
139
162
|
verifyJWT,
|
|
163
|
+
formatRedirectUrl,
|
|
140
164
|
};
|