homebridge-melcloud-control 4.0.0-beta.302 → 4.0.0-beta.304

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.302",
4
+ "version": "4.0.0-beta.304",
5
5
  "description": "Homebridge plugin to control Mitsubishi Air Conditioner, Heat Pump and Energy Recovery Ventilation.",
6
6
  "license": "MIT",
7
7
  "author": "grzegorz914",
@@ -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,25 +78,23 @@ class MelCloudHomeToken {
76
78
  }
77
79
 
78
80
  async getTokens(code) {
79
- const pkce = this.generatePKCE();
80
- const tokenData = new URLSearchParams({
81
+ const data = new URLSearchParams({
81
82
  grant_type: 'authorization_code',
82
83
  code: code,
83
84
  redirect_uri: REDIRECT_URI,
84
85
  client_id: CLIENT_ID,
85
- code_verifier: pkce.verifier,
86
+ code_verifier: this.verifier,
86
87
  });
87
88
 
88
89
  const res = await axios({
89
90
  method: 'POST',
90
- baseURL: TOKEN_ENDPOINT,
91
+ url: TOKEN_ENDPOINT,
91
92
  headers: {
92
93
  'Content-Type': 'application/x-www-form-urlencoded',
93
94
  'Content-Length': tokenData.toString().length,
94
95
  'Authorization': 'Basic aG9tZW1vYmlsZTo='
95
96
  },
96
- data: tokenData,
97
- timeout: 10000
97
+ data: data
98
98
  });
99
99
  console.log(res);
100
100
  if (res.status !== 200) {