homebridge-melcloud-control 4.9.0-beta.8 → 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.
- package/package.json +1 -1
- package/src/melcloudhome.js +17 -9
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.
|
|
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",
|
package/src/melcloudhome.js
CHANGED
|
@@ -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
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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.post(
|
|
422
|
-
headers: {
|
|
423
|
-
|
|
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
|
|
|
@@ -458,7 +466,7 @@ class MelCloudHome extends EventEmitter {
|
|
|
458
466
|
|
|
459
467
|
if (this.logDebug) this.emit('debug', `Got auth code: ${authCode.slice(0, 20)}...`);
|
|
460
468
|
|
|
461
|
-
// ── Step 6: Wymień kod na tokeny ──────────────────
|
|
469
|
+
// ── Step 6: Wymień kod na tokeny (WAŻNE: await!) ──────────────────
|
|
462
470
|
const exchangeRes = await this.exchangeCodeForTokens(client, authCode, codeVerifier);
|
|
463
471
|
return this._buildConnectInfo(connectInfo, exchangeRes);
|
|
464
472
|
|