n8n-nodes-jygse-vw-weconnect 0.1.0 → 0.1.1
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.
|
@@ -164,16 +164,28 @@ async function vwLogin(context, email, password) {
|
|
|
164
164
|
'User-Agent': 'Mozilla/5.0 (Linux; Android 12; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.120 Mobile Safari/537.36',
|
|
165
165
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
|
166
166
|
},
|
|
167
|
+
encoding: 'text',
|
|
167
168
|
returnFullResponse: true,
|
|
168
169
|
ignoreHttpStatusErrors: true,
|
|
169
170
|
});
|
|
170
171
|
// Extract CSRF token and relay state from the response
|
|
171
|
-
|
|
172
|
+
// Handle both string response and object with body property
|
|
173
|
+
let htmlContent;
|
|
174
|
+
if (typeof authorizeResponse === 'string') {
|
|
175
|
+
htmlContent = authorizeResponse;
|
|
176
|
+
}
|
|
177
|
+
else if (authorizeResponse && typeof authorizeResponse === 'object') {
|
|
178
|
+
const respObj = authorizeResponse;
|
|
179
|
+
htmlContent = respObj.body || JSON.stringify(respObj);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
htmlContent = String(authorizeResponse);
|
|
183
|
+
}
|
|
172
184
|
const csrfMatch = htmlContent.match(/name="_csrf"\s+value="([^"]+)"/);
|
|
173
185
|
const relayStateMatch = htmlContent.match(/name="relayState"\s+value="([^"]+)"/);
|
|
174
186
|
const hmacMatch = htmlContent.match(/name="hmac"\s+value="([^"]+)"/);
|
|
175
187
|
if (!csrfMatch) {
|
|
176
|
-
throw new Error(
|
|
188
|
+
throw new Error(`Could not extract CSRF token from login page. Response type: ${typeof authorizeResponse}`);
|
|
177
189
|
}
|
|
178
190
|
const csrf = csrfMatch[1];
|
|
179
191
|
const relayState = relayStateMatch ? relayStateMatch[1] : '';
|
|
@@ -193,11 +205,22 @@ async function vwLogin(context, email, password) {
|
|
|
193
205
|
hmac: hmac,
|
|
194
206
|
email: email,
|
|
195
207
|
}).toString(),
|
|
208
|
+
encoding: 'text',
|
|
196
209
|
returnFullResponse: true,
|
|
197
210
|
ignoreHttpStatusErrors: true,
|
|
198
211
|
});
|
|
199
212
|
// Extract new CSRF for password submission
|
|
200
|
-
|
|
213
|
+
let identifierHtml;
|
|
214
|
+
if (typeof identifierResponse === 'string') {
|
|
215
|
+
identifierHtml = identifierResponse;
|
|
216
|
+
}
|
|
217
|
+
else if (identifierResponse && typeof identifierResponse === 'object') {
|
|
218
|
+
const respObj = identifierResponse;
|
|
219
|
+
identifierHtml = respObj.body || JSON.stringify(respObj);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
identifierHtml = String(identifierResponse);
|
|
223
|
+
}
|
|
201
224
|
const csrf2Match = identifierHtml.match(/name="_csrf"\s+value="([^"]+)"/);
|
|
202
225
|
const relayState2Match = identifierHtml.match(/name="relayState"\s+value="([^"]+)"/);
|
|
203
226
|
const hmac2Match = identifierHtml.match(/name="hmac"\s+value="([^"]+)"/);
|
|
@@ -220,15 +243,26 @@ async function vwLogin(context, email, password) {
|
|
|
220
243
|
email: email,
|
|
221
244
|
password: password,
|
|
222
245
|
}).toString(),
|
|
246
|
+
encoding: 'text',
|
|
223
247
|
returnFullResponse: true,
|
|
224
248
|
ignoreHttpStatusErrors: true,
|
|
225
249
|
});
|
|
226
250
|
// Get the redirect URL which contains the authorization code
|
|
227
|
-
|
|
228
|
-
let
|
|
229
|
-
if (
|
|
230
|
-
|
|
231
|
-
|
|
251
|
+
let redirectUrl = '';
|
|
252
|
+
let authHtml = '';
|
|
253
|
+
if (typeof authResponse === 'string') {
|
|
254
|
+
authHtml = authResponse;
|
|
255
|
+
}
|
|
256
|
+
else if (authResponse && typeof authResponse === 'object') {
|
|
257
|
+
const respObj = authResponse;
|
|
258
|
+
const respHeaders = respObj.headers;
|
|
259
|
+
if (respHeaders && respHeaders.location) {
|
|
260
|
+
redirectUrl = respHeaders.location;
|
|
261
|
+
}
|
|
262
|
+
authHtml = respObj.body || '';
|
|
263
|
+
}
|
|
264
|
+
if (!redirectUrl && authHtml) {
|
|
265
|
+
// Check if we got a redirect in the response HTML
|
|
232
266
|
const redirectMatch = authHtml.match(/URL=([^"]+)"/i);
|
|
233
267
|
if (redirectMatch) {
|
|
234
268
|
redirectUrl = redirectMatch[1];
|
|
@@ -251,11 +285,23 @@ async function vwLogin(context, email, password) {
|
|
|
251
285
|
headers: {
|
|
252
286
|
'User-Agent': 'Mozilla/5.0 (Linux; Android 12; SM-G973F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.120 Mobile Safari/537.36',
|
|
253
287
|
},
|
|
288
|
+
encoding: 'text',
|
|
254
289
|
returnFullResponse: true,
|
|
255
290
|
ignoreHttpStatusErrors: true,
|
|
256
291
|
});
|
|
257
|
-
|
|
258
|
-
|
|
292
|
+
if (typeof followResponse === 'object' && followResponse !== null) {
|
|
293
|
+
const respObj = followResponse;
|
|
294
|
+
const respHeaders = respObj.headers;
|
|
295
|
+
if (respHeaders && respHeaders.location) {
|
|
296
|
+
redirectUrl = respHeaders.location;
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
redirectUrl = '';
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
redirectUrl = '';
|
|
304
|
+
}
|
|
259
305
|
maxRedirects--;
|
|
260
306
|
}
|
|
261
307
|
if (!authCode) {
|
package/package.json
CHANGED