homebridge-lg-thinq-2 2.0.2 → 2.0.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## v2.0.3
4
+
5
+ ### Login
6
+
7
+ * Fixed LG account login failing with `LG pre-login failed: Request failed with status code 403`. LG's account servers now reject requests that identify as axios (the default `axios/<version>` User-Agent), so all plugin requests send a browser User-Agent unless they set their own. Requests to the ThinQ API keep their `okhttp` User-Agent. This affects login from the Homebridge UI, the `thinq` CLI, and username/password config. Based on [nVuln/homebridge-lg-thinq#400](https://github.com/nVuln/homebridge-lg-thinq/pull/400), fixing [nVuln/homebridge-lg-thinq#402](https://github.com/nVuln/homebridge-lg-thinq/issues/402).
8
+ * Added tests that run the login against a local server that rejects the axios User-Agent like LG does.
9
+
3
10
  ## v2.0.2
4
11
 
5
12
  ### Packaging and Releases
package/dist/lib/Auth.js CHANGED
@@ -4,7 +4,7 @@ import qs from 'qs';
4
4
  import { URL } from 'url';
5
5
  import { AuthenticationError, ManualProcessNeededErrorCode, TokenError } from '../errors/index.js';
6
6
  import * as constants from './constants.js';
7
- import { requestClient } from './request.js';
7
+ import { BROWSER_USER_AGENT, requestClient } from './request.js';
8
8
  import { Session } from './Session.js';
9
9
  import { createNoopLogger } from './noopLogger.js';
10
10
  function recordValue(value) {
@@ -152,7 +152,7 @@ export class Auth {
152
152
  'Access-Control-Allow-Origin': '*',
153
153
  'Accept-Encoding': 'gzip, deflate, br',
154
154
  'Accept-Language': 'en-US,en;q=0.9',
155
- 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.44',
155
+ 'User-Agent': BROWSER_USER_AGENT,
156
156
  };
157
157
  // create emp session and get access token
158
158
  const authorize = await requestClient.get(empUrl.href, {
@@ -21,7 +21,21 @@ function errorWithCause(error, cause) {
21
21
  error.cause = cause;
22
22
  return error;
23
23
  }
24
- const client = axios.create();
24
+ /**
25
+ * User-Agent sent with every request unless the caller sets its own.
26
+ *
27
+ * LG's account servers reject requests that identify as axios (the default
28
+ * "axios/<version>" User-Agent) with HTTP 403, for example on POST /spx/preLogin,
29
+ * which made login fail. A browser User-Agent is accepted.
30
+ * See nVuln/homebridge-lg-thinq#402 and nVuln/homebridge-lg-thinq#400.
31
+ */
32
+ export const BROWSER_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 '
33
+ + '(KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.44';
34
+ const client = axios.create({
35
+ headers: {
36
+ 'User-Agent': BROWSER_USER_AGENT,
37
+ },
38
+ });
25
39
  client.defaults.timeout = 60000; // 60s timeout
26
40
  client.interceptors.request.use((config) => {
27
41
  return new Promise((resolve) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Homebridge LG ThinQ 2",
3
3
  "name": "homebridge-lg-thinq-2",
4
- "version": "2.0.2",
4
+ "version": "2.0.3",
5
5
  "description": "Community-maintained continuation of homebridge-lg-thinq: a Homebridge plugin for controlling/monitoring LG ThinQ devices via the LG ThinQ platform.",
6
6
  "license": "Apache-2.0",
7
7
  "type": "module",