homebridge-melcloud-control 4.0.0-beta.303 → 4.0.0-beta.305
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/melcloudhometoken.js +31 -25
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "MELCloud Control",
|
|
3
3
|
"name": "homebridge-melcloud-control",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.305",
|
|
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/melcloudhometoken.js
CHANGED
|
@@ -15,11 +15,13 @@ class MelCloudHomeToken {
|
|
|
15
15
|
const jar = new CookieJar();
|
|
16
16
|
this.client = wrapper(axios.create({ jar, withCredentials: true }));
|
|
17
17
|
this.client.defaults.headers['User-Agent'] = MOBILE_USER_AGENT;
|
|
18
|
+
this.verifier;
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
generatePKCE() {
|
|
21
22
|
const verifier = crypto.randomBytes(32).toString('base64url');
|
|
22
23
|
const challenge = crypto.createHash('sha256').update(verifier).digest('base64url');
|
|
24
|
+
this.verifier = verifier;
|
|
23
25
|
return { verifier, challenge };
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -76,31 +78,35 @@ class MelCloudHomeToken {
|
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
async getTokens(code) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
81
|
+
try {
|
|
82
|
+
const data = new URLSearchParams({
|
|
83
|
+
grant_type: 'authorization_code',
|
|
84
|
+
code: code,
|
|
85
|
+
redirect_uri: REDIRECT_URI,
|
|
86
|
+
client_id: CLIENT_ID,
|
|
87
|
+
code_verifier: this.verifier,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const res = await axios({
|
|
91
|
+
method: 'POST',
|
|
92
|
+
url: TOKEN_ENDPOINT,
|
|
93
|
+
headers: {
|
|
94
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
95
|
+
'Content-Length': tokenData.toString().length,
|
|
96
|
+
'Authorization': 'Basic aG9tZW1vYmlsZTo='
|
|
97
|
+
},
|
|
98
|
+
data: data
|
|
99
|
+
});
|
|
100
|
+
console.log(res);
|
|
101
|
+
if (res.status !== 200) {
|
|
102
|
+
throw new Error(`Token exchange failed: ${res.status} ${res.statusText}`);
|
|
103
|
+
}
|
|
102
104
|
|
|
103
|
-
|
|
105
|
+
return res.data;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error('Failed to obtain OAuth tokens:', error);
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
|
|
@@ -120,7 +126,7 @@ class MelCloudHomeToken {
|
|
|
120
126
|
|
|
121
127
|
return loginPage.url;
|
|
122
128
|
} catch (error) {
|
|
123
|
-
console.error('Failed to obtain OAuth
|
|
129
|
+
console.error('Failed to obtain OAuth link:', error);
|
|
124
130
|
throw error;
|
|
125
131
|
}
|
|
126
132
|
}
|