n8n-nodes-jygse-vw-weconnect 0.1.0 → 0.1.2
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,40 @@ 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
|
+
// Try different possible response structures
|
|
180
|
+
if (respObj.body && typeof respObj.body === 'string') {
|
|
181
|
+
htmlContent = respObj.body;
|
|
182
|
+
}
|
|
183
|
+
else if (respObj.data && typeof respObj.data === 'string') {
|
|
184
|
+
htmlContent = respObj.data;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
// Serialize the object to see its structure in the error
|
|
188
|
+
htmlContent = JSON.stringify(respObj);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
htmlContent = String(authorizeResponse);
|
|
193
|
+
}
|
|
172
194
|
const csrfMatch = htmlContent.match(/name="_csrf"\s+value="([^"]+)"/);
|
|
173
195
|
const relayStateMatch = htmlContent.match(/name="relayState"\s+value="([^"]+)"/);
|
|
174
196
|
const hmacMatch = htmlContent.match(/name="hmac"\s+value="([^"]+)"/);
|
|
175
197
|
if (!csrfMatch) {
|
|
176
|
-
|
|
198
|
+
// Show first 500 chars of response for debugging
|
|
199
|
+
const preview = htmlContent.substring(0, 500);
|
|
200
|
+
throw new Error(`Could not extract CSRF token. Response preview: ${preview}`);
|
|
177
201
|
}
|
|
178
202
|
const csrf = csrfMatch[1];
|
|
179
203
|
const relayState = relayStateMatch ? relayStateMatch[1] : '';
|
|
@@ -193,11 +217,22 @@ async function vwLogin(context, email, password) {
|
|
|
193
217
|
hmac: hmac,
|
|
194
218
|
email: email,
|
|
195
219
|
}).toString(),
|
|
220
|
+
encoding: 'text',
|
|
196
221
|
returnFullResponse: true,
|
|
197
222
|
ignoreHttpStatusErrors: true,
|
|
198
223
|
});
|
|
199
224
|
// Extract new CSRF for password submission
|
|
200
|
-
|
|
225
|
+
let identifierHtml;
|
|
226
|
+
if (typeof identifierResponse === 'string') {
|
|
227
|
+
identifierHtml = identifierResponse;
|
|
228
|
+
}
|
|
229
|
+
else if (identifierResponse && typeof identifierResponse === 'object') {
|
|
230
|
+
const respObj = identifierResponse;
|
|
231
|
+
identifierHtml = respObj.body || JSON.stringify(respObj);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
identifierHtml = String(identifierResponse);
|
|
235
|
+
}
|
|
201
236
|
const csrf2Match = identifierHtml.match(/name="_csrf"\s+value="([^"]+)"/);
|
|
202
237
|
const relayState2Match = identifierHtml.match(/name="relayState"\s+value="([^"]+)"/);
|
|
203
238
|
const hmac2Match = identifierHtml.match(/name="hmac"\s+value="([^"]+)"/);
|
|
@@ -220,15 +255,26 @@ async function vwLogin(context, email, password) {
|
|
|
220
255
|
email: email,
|
|
221
256
|
password: password,
|
|
222
257
|
}).toString(),
|
|
258
|
+
encoding: 'text',
|
|
223
259
|
returnFullResponse: true,
|
|
224
260
|
ignoreHttpStatusErrors: true,
|
|
225
261
|
});
|
|
226
262
|
// Get the redirect URL which contains the authorization code
|
|
227
|
-
|
|
228
|
-
let
|
|
229
|
-
if (
|
|
230
|
-
|
|
231
|
-
|
|
263
|
+
let redirectUrl = '';
|
|
264
|
+
let authHtml = '';
|
|
265
|
+
if (typeof authResponse === 'string') {
|
|
266
|
+
authHtml = authResponse;
|
|
267
|
+
}
|
|
268
|
+
else if (authResponse && typeof authResponse === 'object') {
|
|
269
|
+
const respObj = authResponse;
|
|
270
|
+
const respHeaders = respObj.headers;
|
|
271
|
+
if (respHeaders && respHeaders.location) {
|
|
272
|
+
redirectUrl = respHeaders.location;
|
|
273
|
+
}
|
|
274
|
+
authHtml = respObj.body || '';
|
|
275
|
+
}
|
|
276
|
+
if (!redirectUrl && authHtml) {
|
|
277
|
+
// Check if we got a redirect in the response HTML
|
|
232
278
|
const redirectMatch = authHtml.match(/URL=([^"]+)"/i);
|
|
233
279
|
if (redirectMatch) {
|
|
234
280
|
redirectUrl = redirectMatch[1];
|
|
@@ -251,11 +297,23 @@ async function vwLogin(context, email, password) {
|
|
|
251
297
|
headers: {
|
|
252
298
|
'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
299
|
},
|
|
300
|
+
encoding: 'text',
|
|
254
301
|
returnFullResponse: true,
|
|
255
302
|
ignoreHttpStatusErrors: true,
|
|
256
303
|
});
|
|
257
|
-
|
|
258
|
-
|
|
304
|
+
if (typeof followResponse === 'object' && followResponse !== null) {
|
|
305
|
+
const respObj = followResponse;
|
|
306
|
+
const respHeaders = respObj.headers;
|
|
307
|
+
if (respHeaders && respHeaders.location) {
|
|
308
|
+
redirectUrl = respHeaders.location;
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
redirectUrl = '';
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
redirectUrl = '';
|
|
316
|
+
}
|
|
259
317
|
maxRedirects--;
|
|
260
318
|
}
|
|
261
319
|
if (!authCode) {
|
package/package.json
CHANGED