n8n-nodes-jygse-vw-weconnect 0.1.4 → 0.1.5

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.
@@ -189,19 +189,24 @@ async function vwLogin(context, email, password) {
189
189
  encoding: 'text',
190
190
  returnFullResponse: true,
191
191
  ignoreHttpStatusErrors: true,
192
+ skipAutoFollowRedirects: true,
192
193
  });
193
194
  // Extract response body and check for redirect
194
195
  let htmlContent;
195
196
  let currentUrl = '';
197
+ let stateToken = '';
196
198
  if (typeof authorizeResponse === 'string') {
197
199
  htmlContent = authorizeResponse;
198
200
  }
199
201
  else if (authorizeResponse && typeof authorizeResponse === 'object') {
200
202
  const respObj = authorizeResponse;
201
203
  const respHeaders = respObj.headers;
202
- // Check for redirect in headers
203
- if (respHeaders && respHeaders.location) {
204
- currentUrl = respHeaders.location;
204
+ // Check for redirect in headers (case-insensitive)
205
+ if (respHeaders) {
206
+ const locationHeader = respHeaders.location || respHeaders.Location;
207
+ if (locationHeader) {
208
+ currentUrl = locationHeader;
209
+ }
205
210
  }
206
211
  if (respObj.body && typeof respObj.body === 'string') {
207
212
  htmlContent = respObj.body;
@@ -216,15 +221,56 @@ async function vwLogin(context, email, password) {
216
221
  else {
217
222
  htmlContent = String(authorizeResponse);
218
223
  }
219
- // Try to extract state token from Auth0 page (new flow)
220
- // Look for state in URL or in hidden form field
221
- let stateToken = '';
222
- // Check if we were redirected to /u/login
223
- const stateUrlMatch = currentUrl.match(/state=([^&]+)/);
224
- if (stateUrlMatch) {
225
- stateToken = decodeURIComponent(stateUrlMatch[1]);
224
+ // Follow redirects manually to capture the state parameter
225
+ let maxInitialRedirects = 5;
226
+ while (currentUrl && maxInitialRedirects > 0) {
227
+ // Extract state from redirect URL
228
+ const stateMatch = currentUrl.match(/state=([^&]+)/);
229
+ if (stateMatch) {
230
+ stateToken = decodeURIComponent(stateMatch[1]);
231
+ }
232
+ // If we reached the /u/login page, we have what we need
233
+ if (currentUrl.includes('/u/login') && stateToken) {
234
+ break;
235
+ }
236
+ // Follow the redirect
237
+ const followUrl = currentUrl.startsWith('http') ? currentUrl : `https://identity.vwgroup.io${currentUrl}`;
238
+ const followResponse = await context.helpers.httpRequest({
239
+ method: 'GET',
240
+ url: followUrl,
241
+ headers: {
242
+ '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',
243
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
244
+ },
245
+ encoding: 'text',
246
+ returnFullResponse: true,
247
+ ignoreHttpStatusErrors: true,
248
+ skipAutoFollowRedirects: true,
249
+ });
250
+ if (typeof followResponse === 'string') {
251
+ htmlContent = followResponse;
252
+ currentUrl = '';
253
+ }
254
+ else if (followResponse && typeof followResponse === 'object') {
255
+ const respObj = followResponse;
256
+ const respHeaders = respObj.headers;
257
+ currentUrl = '';
258
+ if (respHeaders) {
259
+ const locationHeader = respHeaders.location || respHeaders.Location;
260
+ if (locationHeader) {
261
+ currentUrl = locationHeader;
262
+ }
263
+ }
264
+ if (respObj.body && typeof respObj.body === 'string') {
265
+ htmlContent = respObj.body;
266
+ }
267
+ else if (respObj.data && typeof respObj.data === 'string') {
268
+ htmlContent = respObj.data;
269
+ }
270
+ }
271
+ maxInitialRedirects--;
226
272
  }
227
- // Also try to find state in the HTML
273
+ // Try to extract state token from the final HTML if not found in URL
228
274
  if (!stateToken) {
229
275
  const stateHtmlMatch = htmlContent.match(/name="state"\s+value="([^"]+)"/);
230
276
  if (stateHtmlMatch) {
@@ -238,6 +284,13 @@ async function vwLogin(context, email, password) {
238
284
  stateToken = decodeURIComponent(formActionMatch[1]);
239
285
  }
240
286
  }
287
+ // Try to extract state from any URL in the page
288
+ if (!stateToken) {
289
+ const anyStateMatch = htmlContent.match(/state=([a-zA-Z0-9_.-]+)/);
290
+ if (anyStateMatch) {
291
+ stateToken = anyStateMatch[1];
292
+ }
293
+ }
241
294
  // Try legacy CSRF-based flow first
242
295
  const csrfMatch = htmlContent.match(/name="_csrf"\s+value="([^"]+)"/);
243
296
  const relayStateMatch = htmlContent.match(/name="relayState"\s+value="([^"]+)"/);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-jygse-vw-weconnect",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "n8n community node for VW We Connect - Control your Volkswagen T6.1 and other VW vehicles",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",