homebridge-melcloud-control 4.3.11-beta.17 → 4.3.11-beta.19

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/index.js CHANGED
@@ -105,8 +105,8 @@ class MelCloudPlatform {
105
105
 
106
106
  //connect
107
107
  const accountInfo = await melcloud.connect();
108
- if (!accountInfo.State) {
109
- if (logLevel.warn) log.warn(`${accountName}, ${accountInfo.Info}`);
108
+ if (!accountInfo?.State) {
109
+ if (logLevel.warn) log.warn(`${accountName}, ${accountInfo?.Info}`);
110
110
  return;
111
111
  }
112
112
  if (logLevel.success) log.success(`${accountName}, ${accountInfo.Info}`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.3.11-beta.17",
4
+ "version": "4.3.11-beta.19",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -104,7 +104,7 @@ class MELCloudHomeAuth {
104
104
  _csrf: csrf,
105
105
  username,
106
106
  password,
107
- cognitoAsfData: "", // placeholder; may be required if Cognito enforces advanced security
107
+ cognitoAsfData: "",
108
108
  });
109
109
 
110
110
  const resp = await this.axios.post(loginUrl, payload.toString(), {
@@ -113,39 +113,48 @@ class MELCloudHomeAuth {
113
113
  Origin: COGNITO_BASE,
114
114
  Referer: loginUrl,
115
115
  },
116
- maxRedirects: 10,
117
116
  validateStatus: () => true,
117
+ maxRedirects: 0
118
118
  });
119
119
 
120
- const finalUrl =
121
- resp.request?.res?.responseUrl || resp.config?.url || "unknown";
122
-
123
- this.log("Post-login final URL:", finalUrl, "status:", resp.status);
120
+ const redirectUrl =
121
+ resp.headers.location ||
122
+ resp.request?.res?.responseUrl ||
123
+ resp.config.url;
124
124
 
125
- // Common failure patterns
126
- if (finalUrl.includes("/error") || resp.status >= 400) {
127
- // try extract error message
128
- const errMsg = this.extractErrorMessage(resp.data) || "Unknown error from Cognito";
129
- throw new Error(`Authentication failed: ${errMsg}`);
125
+ if (!redirectUrl.includes("signin-oidc")) {
126
+ throw new Error("Authentication failed: signin-oidc callback not received");
130
127
  }
131
128
 
132
- // If still on Cognito domain -> bad credentials or MFA required
133
- if (finalUrl.includes("amazoncognito.com")) {
134
- throw new Error("Authentication failed: invalid username/password or additional challenge required");
135
- }
129
+ this.log("Calling signin-oidc:", redirectUrl);
136
130
 
137
- // Success: redirected back to melcloudhome domain
138
- if (finalUrl.includes("melcloudhome.com")) {
139
- this.authenticated = true;
140
- this.log("Successfully authenticated, session cookies stored.");
141
- // Wait a short time for Blazor / client initialization (server may set additional cookies)
142
- await this._delay(2500);
143
- return true;
131
+ // --- MEGA WAŻNE: wywołać callback ---
132
+ const callback = await this.axios.get(redirectUrl, {
133
+ headers: {
134
+ Referer: loginUrl,
135
+ "User-Agent": USER_AGENT,
136
+ Accept: "text/html",
137
+ },
138
+ validateStatus: () => true
139
+ });
140
+
141
+ this.log("signin-oidc status:", callback.status);
142
+
143
+ // Status 500 JEST NORMALNY – liczą się cookies!
144
+ const cookies = await this.jar.getCookies(redirectUrl);
145
+ this.log("After signin-oidc cookies:", cookies.map(c => c.key));
146
+
147
+ // Jeżeli pojawił się cookie `meu.identity` – logowanie jest zakończone
148
+ const hasIdentity = cookies.some(c => c.key.includes("meu.identity"));
149
+ if (!hasIdentity) {
150
+ throw new Error("openid callback did not produce a session cookie");
144
151
  }
145
152
 
146
- throw new Error(`Unexpected redirect after login: ${finalUrl}`);
153
+ this.authenticated = true;
154
+ return true;
147
155
  }
148
156
 
157
+
149
158
  // Public login method
150
159
  async login(username, password) {
151
160
  try {