homebridge-melcloud-control 4.0.0-beta.305 → 4.0.0-beta.307

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "MELCloud Control",
3
3
  "name": "homebridge-melcloud-control",
4
- "version": "4.0.0-beta.305",
4
+ "version": "4.0.0-beta.307",
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/melcloud.js CHANGED
@@ -290,10 +290,10 @@ class MelCloud extends EventEmitter {
290
290
  });
291
291
 
292
292
  const melCloudHomeToken = new MelCloudHomeToken();
293
- const url = await melCloudHomeToken.buildAuthorizeUrl();
293
+ const data = await melCloudHomeToken.buildAuthorizeUrl();
294
294
 
295
295
  const page = await browser.newPage();
296
- await page.goto(url, { waitUntil: 'networkidle2' });
296
+ await page.goto(data.url, { waitUntil: 'networkidle2' });
297
297
 
298
298
  await page.waitForSelector('input[name="username"]', { timeout: 5000 });
299
299
  await page.type('input[name="username"]', this.user, { delay: 50 });
@@ -305,7 +305,7 @@ class MelCloud extends EventEmitter {
305
305
  this.emit('warn', code);
306
306
 
307
307
  // 5. Wymień code na access_token
308
- const tokenResponse = await melCloudHomeToken.getTokens(code);
308
+ const tokenResponse = await melCloudHomeToken.getTokens(code, data.codeVerifier);
309
309
  const tokenData = await tokenResponse.json();
310
310
  this.emit('debug', `Token: ${JSON.stringify(tokenData, null, 2)}`);
311
311
  const accountInfo = {
@@ -15,13 +15,11 @@ 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;
19
18
  }
20
19
 
21
20
  generatePKCE() {
22
21
  const verifier = crypto.randomBytes(32).toString('base64url');
23
22
  const challenge = crypto.createHash('sha256').update(verifier).digest('base64url');
24
- this.verifier = verifier;
25
23
  return { verifier, challenge };
26
24
  }
27
25
 
@@ -77,14 +75,14 @@ class MelCloudHomeToken {
77
75
  }
78
76
  }
79
77
 
80
- async getTokens(code) {
78
+ async getTokens(code, codeVerifier) {
81
79
  try {
82
80
  const data = new URLSearchParams({
83
81
  grant_type: 'authorization_code',
84
82
  code: code,
85
83
  redirect_uri: REDIRECT_URI,
86
84
  client_id: CLIENT_ID,
87
- code_verifier: this.verifier,
85
+ code_verifier: codeVerifier,
88
86
  });
89
87
 
90
88
  const res = await axios({
@@ -92,7 +90,7 @@ class MelCloudHomeToken {
92
90
  url: TOKEN_ENDPOINT,
93
91
  headers: {
94
92
  'Content-Type': 'application/x-www-form-urlencoded',
95
- 'Content-Length': tokenData.toString().length,
93
+ 'Content-Length': data.toString().length,
96
94
  'Authorization': 'Basic aG9tZW1vYmlsZTo='
97
95
  },
98
96
  data: data
@@ -124,7 +122,8 @@ class MelCloudHomeToken {
124
122
  authUrl.searchParams.set('state', state);
125
123
  const loginPage = await this.getLoginPage(authUrl.toString());
126
124
 
127
- return loginPage.url;
125
+ const data = { codeVerifier: pkce.verifier, url: loginPage.url }
126
+ return data;
128
127
  } catch (error) {
129
128
  console.error('Failed to obtain OAuth link:', error);
130
129
  throw error;