homebridge-lg-thinq-2 2.0.16 → 2.0.17
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 +7 -0
- package/README.md +1 -0
- package/dist/lib/Auth.js +34 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## v2.0.17
|
|
4
|
+
|
|
5
|
+
### Login
|
|
6
|
+
|
|
7
|
+
* Fixed LG account sign-in failing with `LG OAuth key lookup failed: Request failed with status code 404`. LG removed the `searchKey` endpoint, which returned the secret used to sign the sign-in request, and now signs that request on its own server, as LG's sign-in page does. The plugin now asks LG's sign-in service for the signature and checks that the answer is a signature. The same approach was first used in the [@rnikoopour/homebridge-lg-thinq](https://www.npmjs.com/package/@rnikoopour/homebridge-lg-thinq) and [@robotpool/homebridge-lg-thinq](https://www.npmjs.com/package/@robotpool/homebridge-lg-thinq) forks.
|
|
8
|
+
* Documented the error in the README troubleshooting table.
|
|
9
|
+
|
|
3
10
|
## v2.0.16
|
|
4
11
|
|
|
5
12
|
### Dependencies
|
package/README.md
CHANGED
|
@@ -219,6 +219,7 @@ Turn on Homebridge **debug mode** (Homebridge UI → Settings) to see detailed l
|
|
|
219
219
|
|
|
220
220
|
| Problem | What to do |
|
|
221
221
|
| --- | --- |
|
|
222
|
+
| `LG OAuth key lookup failed: Request failed with status code 404` | LG removed the sign-in step this message comes from. Update to version `2.0.17` or later. |
|
|
222
223
|
| `LG pre-login failed: Request failed with status code 403` | LG rejected the login request. Update to version `2.0.3` or later. |
|
|
223
224
|
| `Request failed with status code 429` or result code `9012` | LG received too many requests. Update to version `2.0.6` or later, and do not set a low `refresh_interval`. |
|
|
224
225
|
| `LG has locked sign-in for this account` (LG message `Need Sign-In Unlock`) | LG locked sign-in, usually after several failed sign-ins or a sign-in from a new device. Sign in to the LG ThinQ app or to your LG account on the LG website and complete the verification LG asks for, then try again. Or get a refresh token with [`thinq auth`](#command-line-tool), which uses LG's sign-in page. |
|
package/dist/lib/Auth.js
CHANGED
|
@@ -46,6 +46,8 @@ export function authErrorMessage(err, fallback) {
|
|
|
46
46
|
|| (errorCause(err) ? authErrorMessage(errorCause(err), fallback) : null)
|
|
47
47
|
|| fallback;
|
|
48
48
|
}
|
|
49
|
+
// A base64 HMAC signature, as returned by LG's sign-in service (28 characters for HMAC-SHA1).
|
|
50
|
+
const EMP_SIGNATURE_PATTERN = /^[A-Za-z0-9+/]{16,128}={0,2}$/;
|
|
49
51
|
export const SIGN_IN_UNLOCK_MESSAGE = 'LG has locked sign-in for this account and asks to unlock it '
|
|
50
52
|
+ '(LG message: "Need Sign-In Unlock"). This usually happens after several failed sign-ins or a sign-in '
|
|
51
53
|
+ 'from a new device. Sign in to the LG ThinQ app or to your LG account on the LG website and complete '
|
|
@@ -139,12 +141,6 @@ export class Auth {
|
|
|
139
141
|
}
|
|
140
142
|
throw new AuthenticationError(message);
|
|
141
143
|
});
|
|
142
|
-
// dynamic get secret key for emp signature
|
|
143
|
-
const empSearchKeyUrl = this.gateway.login_base_url + 'searchKey?key_name=OAUTH_SECRETKEY&sever_type=OP';
|
|
144
|
-
const secretKey = await requestClient.get(empSearchKeyUrl).then(res => res.data).then(data => data.returnData)
|
|
145
|
-
.catch(err => {
|
|
146
|
-
throw authError('LG OAuth key lookup failed', err);
|
|
147
|
-
});
|
|
148
144
|
const timestamp = DateTime.utc().toRFC2822();
|
|
149
145
|
const empData = {
|
|
150
146
|
account_type: account.userIDType,
|
|
@@ -156,7 +152,7 @@ export class Auth {
|
|
|
156
152
|
username: account.userID,
|
|
157
153
|
};
|
|
158
154
|
const empUrl = new URL('https://emp-oauth.lgecloud.com/emp/oauth2/authorize/empsession?' + qs.stringify(empData));
|
|
159
|
-
const signature = this.
|
|
155
|
+
const signature = await this.requestEmpSignature(`${empUrl.pathname}${empUrl.search}\n${timestamp}`);
|
|
160
156
|
const empHeaders = {
|
|
161
157
|
'lgemp-x-app-key': constants.OAUTH_CLIENT_KEY,
|
|
162
158
|
'lgemp-x-date': timestamp,
|
|
@@ -411,6 +407,37 @@ export class Auth {
|
|
|
411
407
|
* @param secret - The secret key used for signing.
|
|
412
408
|
* @returns The generated signature.
|
|
413
409
|
*/
|
|
410
|
+
/**
|
|
411
|
+
* Has LG's sign-in service sign an EMP OAuth request.
|
|
412
|
+
*
|
|
413
|
+
* LG removed the `searchKey` endpoint, which returned the signing secret to the
|
|
414
|
+
* client (it answers HTTP 404 in every region), and now signs the message on its
|
|
415
|
+
* server, as LG's own sign-in page does. The parameters, including LG's
|
|
416
|
+
* `sever_type` spelling, are the ones that page sends.
|
|
417
|
+
*
|
|
418
|
+
* @param message - The request path and query, a new line, and the RFC 2822 date.
|
|
419
|
+
* @returns The base64 HMAC signature for the `lgemp-x-signature` header.
|
|
420
|
+
*/
|
|
421
|
+
async requestEmpSignature(message) {
|
|
422
|
+
const signatureUrl = this.gateway.login_base_url + 'signature?' + qs.stringify({
|
|
423
|
+
kind: 'oauth2',
|
|
424
|
+
timestamp: message,
|
|
425
|
+
key_name: 'OAUTH_SECRETKEY',
|
|
426
|
+
sever_type: 'OP',
|
|
427
|
+
});
|
|
428
|
+
const body = await requestClient.get(signatureUrl, {
|
|
429
|
+
headers: { 'Accept': 'text/plain, */*' },
|
|
430
|
+
responseType: 'text',
|
|
431
|
+
transformResponse: [(data) => data],
|
|
432
|
+
}).then(res => res.data).catch(err => {
|
|
433
|
+
throw authError('LG OAuth signature request failed', err);
|
|
434
|
+
});
|
|
435
|
+
const signature = typeof body === 'string' ? body.trim() : '';
|
|
436
|
+
if (!EMP_SIGNATURE_PATTERN.test(signature)) {
|
|
437
|
+
throw new AuthenticationError('LG OAuth signature request failed: unexpected response from the LG sign-in service.');
|
|
438
|
+
}
|
|
439
|
+
return signature;
|
|
440
|
+
}
|
|
414
441
|
signature(message, secret) {
|
|
415
442
|
return crypto.createHmac('sha1', Buffer.from(secret)).update(message).digest('base64');
|
|
416
443
|
}
|
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.
|
|
4
|
+
"version": "2.0.17",
|
|
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",
|