homebridge-melcloud-control 4.9.0-beta.7 → 4.9.0-beta.9

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/melcloudhome.js +19 -11
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.9.0-beta.7",
4
+ "version": "4.9.0-beta.9",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -34,7 +34,7 @@ class MelCloudHome extends EventEmitter {
34
34
 
35
35
  // axios auth client and token state
36
36
  this.authClient = null;
37
- this._accessToken = null;
37
+ this._accessToken = null; // podkreślnik — unika konfliktu z getterami
38
38
  this._refreshToken = null;
39
39
  this._tokenExpiry = 0; // Unix timestamp (sekundy)
40
40
  this._authenticated = false;
@@ -412,15 +412,23 @@ class MelCloudHome extends EventEmitter {
412
412
 
413
413
  if (this.logDebug) this.emit('debug', `Step 4 location: ${cognitoRedirectLocation}`);
414
414
 
415
- const signinUrl = cognitoRedirectLocation.startsWith('http')
416
- ? cognitoRedirectLocation
417
- : `https://${cognitoHostname}${cognitoRedirectLocation}`;
415
+ // signin-oidc-meu to endpoint IdentityServera obsługujący callback z Cognito.
416
+ // Cognito normalnie robi tam form_post (POST z code i state w body),
417
+ // ale my dostaliśmy 302 z parametrami w query stringu — wysyłamy więc POST
418
+ // z tymi samymi parametrami w body (tak jak zrobiłoby to Cognito).
419
+ const signinParsed = new URL(cognitoRedirectLocation);
420
+ const signinBase = `${signinParsed.protocol}//${signinParsed.host}${signinParsed.pathname}`;
421
+ const signinParams = new URLSearchParams(signinParsed.search);
422
+
423
+ if (this.logDebug) this.emit('debug', `Step 4 POST to: ${signinBase} params: ${[...signinParams.keys()].join(', ')}`);
418
424
 
419
- // GET na signin-oidc-meu — IdentityServer przetworzy i przekieruje do melcloudhome://
420
425
  const signinResp = await this.pace(() =>
421
- client.get(signinUrl, {
422
- headers: { 'User-Agent': ApiUrls.Home.UserAgent },
423
- maxRedirects: 0, // przechwytujemy redirect do melcloudhome://
426
+ client.post(signinBase, signinParams, {
427
+ headers: {
428
+ 'User-Agent': ApiUrls.Home.UserAgent,
429
+ 'Content-Type': 'application/x-www-form-urlencoded',
430
+ },
431
+ maxRedirects: 0,
424
432
  })
425
433
  );
426
434
 
@@ -436,11 +444,11 @@ class MelCloudHome extends EventEmitter {
436
444
  const signinBody = typeof signinResp.data === 'string' ? signinResp.data : '';
437
445
 
438
446
  // Przypadek A: bezpośredni redirect na melcloudhome://
439
- let codeMatch = /code=([^&"' ]+)/.exec(cognitoRedirectLocation);
447
+ let codeMatch = /code=([^&"' ]+)/.exec(signinLocation);
440
448
 
441
449
  // Przypadek B: IdentityServer przekierowuje do /connect/authorize/callback
442
450
  if (!codeMatch) {
443
- const callbackMatch = /\/connect\/authorize\/callback\?([^"' ]+)/.exec(cognitoRedirectLocation)
451
+ const callbackMatch = /\/connect\/authorize\/callback\?([^"' ]+)/.exec(signinLocation)
444
452
  || /\/connect\/authorize\/callback\?([^"' ]+)/.exec(signinBody);
445
453
 
446
454
  if (callbackMatch) {
@@ -449,7 +457,7 @@ class MelCloudHome extends EventEmitter {
449
457
  } else {
450
458
  // Przypadek C: kod bezpośrednio w body (np. form hidden field)
451
459
  codeMatch = /code=([^&"' ]+)/.exec(signinBody);
452
- if (!codeMatch) throw new Error(`Failed to extract auth code. signin status=${signinResp.status}, location=${cognitoRedirectLocation}`);
460
+ if (!codeMatch) throw new Error(`Failed to extract auth code. signin status=${signinResp.status}, location=${signinLocation}`);
453
461
  authCode = codeMatch[1];
454
462
  }
455
463
  } else {