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 +2 -2
- package/package.json +1 -1
- package/src/melcloudhomeauth.js +32 -23
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
|
|
109
|
-
if (logLevel.warn) log.warn(`${accountName}, ${accountInfo
|
|
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.
|
|
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",
|
package/src/melcloudhomeauth.js
CHANGED
|
@@ -104,7 +104,7 @@ class MELCloudHomeAuth {
|
|
|
104
104
|
_csrf: csrf,
|
|
105
105
|
username,
|
|
106
106
|
password,
|
|
107
|
-
cognitoAsfData: "",
|
|
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
|
|
121
|
-
resp.
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
const redirectUrl =
|
|
121
|
+
resp.headers.location ||
|
|
122
|
+
resp.request?.res?.responseUrl ||
|
|
123
|
+
resp.config.url;
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
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 {
|