homebridge-lg-thinq-2 2.0.16 → 2.0.18
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 +19 -0
- package/README.md +25 -1
- package/dist/lib/Auth.js +34 -7
- package/homebridge-ui/public/index.html +46 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## v2.0.18
|
|
4
|
+
|
|
5
|
+
### Homebridge UI
|
|
6
|
+
|
|
7
|
+
* The guide link in **Other login methods** now opens in a new browser tab. It opened inside the settings window, where GitHub refuses to be shown ("This content is blocked").
|
|
8
|
+
* The link now goes to a new [Other sign-in methods](README.md#other-sign-in-methods) section of the README instead of the original project's wiki, which told users to install the original package.
|
|
9
|
+
* **Other login methods** has a field to paste a refresh token from the `thinq` command and use it, instead of editing the config JSON.
|
|
10
|
+
|
|
11
|
+
### Documentation
|
|
12
|
+
|
|
13
|
+
* Added the Other sign-in methods section to the README: getting a refresh token with `npx -y -p homebridge-lg-thinq-2 thinq ... auth` (works with Google, Apple, and Facebook accounts), and using a second LG account.
|
|
14
|
+
|
|
15
|
+
## v2.0.17
|
|
16
|
+
|
|
17
|
+
### Login
|
|
18
|
+
|
|
19
|
+
* 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.
|
|
20
|
+
* Documented the error in the README troubleshooting table.
|
|
21
|
+
|
|
3
22
|
## v2.0.16
|
|
4
23
|
|
|
5
24
|
### Dependencies
|
package/README.md
CHANGED
|
@@ -108,7 +108,30 @@ The device cache is stored in a new folder, so the first start can take a little
|
|
|
108
108
|
|
|
109
109
|
If no devices are listed in the configuration, all supported devices in the LG account are added. Add device entries only to rename devices, change device options, or add only some devices.
|
|
110
110
|
|
|
111
|
-
If you sign in to LG with Google, Apple, or
|
|
111
|
+
If you sign in to LG with Google, Apple, or Facebook, or the sign-in does not work for your account, see [Other sign-in methods](#other-sign-in-methods).
|
|
112
|
+
|
|
113
|
+
### Other sign-in methods
|
|
114
|
+
|
|
115
|
+
#### Get a refresh token with the `thinq` command
|
|
116
|
+
|
|
117
|
+
The command opens LG's own sign-in page, so it works with Google, Apple, and Facebook accounts, and with any verification LG asks for. You need Node.js 22 or later on any computer.
|
|
118
|
+
|
|
119
|
+
1. Run the command with your account's country and language, for example for Spain:
|
|
120
|
+
|
|
121
|
+
```sh
|
|
122
|
+
npx -y -p homebridge-lg-thinq-2 thinq -c ES -l es-ES auth
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
2. Open the link that the command prints, and sign in to LG.
|
|
126
|
+
3. When the sign-in finishes, the browser goes to a page that may be blank or show an error. Copy the full address from the address bar and paste it in the terminal.
|
|
127
|
+
4. The command prints `Your refresh_token: ...`.
|
|
128
|
+
5. In the plugin settings, open **Other login methods**, paste the token, and click **Use Token**. Then click **Save** and restart Homebridge.
|
|
129
|
+
|
|
130
|
+
Keep the refresh token private: it gives access to your LG devices.
|
|
131
|
+
|
|
132
|
+
#### Use a second LG account
|
|
133
|
+
|
|
134
|
+
Accounts created with Google, Apple, or Facebook have no password that the plugin can use. Create a second LG account with an email and password, share your home with it from the LG ThinQ app, and sign in with that account in the plugin settings. LG treats it as a separate account, even with the same email address.
|
|
112
135
|
|
|
113
136
|
### Manual configuration
|
|
114
137
|
|
|
@@ -219,6 +242,7 @@ Turn on Homebridge **debug mode** (Homebridge UI → Settings) to see detailed l
|
|
|
219
242
|
|
|
220
243
|
| Problem | What to do |
|
|
221
244
|
| --- | --- |
|
|
245
|
+
| `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
246
|
| `LG pre-login failed: Request failed with status code 403` | LG rejected the login request. Update to version `2.0.3` or later. |
|
|
223
247
|
| `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
248
|
| `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
|
}
|
|
@@ -290,7 +290,19 @@
|
|
|
290
290
|
</div>
|
|
291
291
|
<div aria-labelledby="headingTwo" class="collapse" id="collapseTwo">
|
|
292
292
|
<div class="card-body">
|
|
293
|
-
<p>
|
|
293
|
+
<p>
|
|
294
|
+
If you sign in to LG with Google, Apple, or Facebook, or prefer not to enter your password here,
|
|
295
|
+
get a refresh token with the <code>thinq</code> command and paste it below. The
|
|
296
|
+
<a href="https://github.com/santiagosony/homebridge-lg-thinq-2#other-sign-in-methods" target="_blank" rel="noopener noreferrer"><b>Other sign-in methods</b></a>
|
|
297
|
+
guide explains how.
|
|
298
|
+
</p>
|
|
299
|
+
<div class="mb-3">
|
|
300
|
+
<label class="form-label" for="refreshTokenInput">Refresh token</label>
|
|
301
|
+
<input autocomplete="off" class="form-control" id="refreshTokenInput" spellcheck="false" type="password">
|
|
302
|
+
</div>
|
|
303
|
+
<div class="text-center mt-3">
|
|
304
|
+
<button class="btn btn-primary" id="useTokenButton" type="button">Use Token</button>
|
|
305
|
+
</div>
|
|
294
306
|
</div>
|
|
295
307
|
</div>
|
|
296
308
|
</div>
|
|
@@ -351,6 +363,18 @@
|
|
|
351
363
|
return error?.error || error?.message || fallback;
|
|
352
364
|
}
|
|
353
365
|
|
|
366
|
+
// Stores a refresh token in the config and shows the settings, as after a successful login.
|
|
367
|
+
async function applyRefreshToken(configuration, refreshToken) {
|
|
368
|
+
configuration.auth_mode = 'token';
|
|
369
|
+
configuration.refresh_token = refreshToken;
|
|
370
|
+
await homebridge.updatePluginConfig([configuration]);
|
|
371
|
+
homebridge.enableSaveButton();
|
|
372
|
+
|
|
373
|
+
await renderConfigForm(configuration, { hideDevices: true });
|
|
374
|
+
hideElement(byId('loginForm'));
|
|
375
|
+
showSaveNotice();
|
|
376
|
+
}
|
|
377
|
+
|
|
354
378
|
function setLoginButtonLoading(btn, label) {
|
|
355
379
|
btn.disabled = true;
|
|
356
380
|
btn.innerHTML = '<span class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true"></span>';
|
|
@@ -688,6 +712,26 @@
|
|
|
688
712
|
await homebridge.updatePluginConfig([configuration]);
|
|
689
713
|
});
|
|
690
714
|
|
|
715
|
+
byId('useTokenButton').addEventListener('click', async (e) => {
|
|
716
|
+
e.preventDefault();
|
|
717
|
+
const refreshToken = byId('refreshTokenInput').value.trim();
|
|
718
|
+
if (!refreshToken) {
|
|
719
|
+
homebridge.toast.error('Paste the refresh token from the thinq command first.', 'Error');
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
const btn = e.currentTarget;
|
|
724
|
+
btn.disabled = true;
|
|
725
|
+
try {
|
|
726
|
+
await applyRefreshToken(configuration, refreshToken);
|
|
727
|
+
byId('refreshTokenInput').value = '';
|
|
728
|
+
}
|
|
729
|
+
catch (error) {
|
|
730
|
+
homebridge.toast.error(requestErrorMessage(error, 'Unable to save the refresh token.'), 'Error');
|
|
731
|
+
btn.disabled = false;
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
|
|
691
735
|
byId('getTokenButton').addEventListener('click', async (e) => {
|
|
692
736
|
e.preventDefault();
|
|
693
737
|
const username = byId('usernameInput').value;
|
|
@@ -710,7 +754,6 @@
|
|
|
710
754
|
resetLoginButton(btn);
|
|
711
755
|
}
|
|
712
756
|
else {
|
|
713
|
-
configuration.refresh_token = data.token;
|
|
714
757
|
if (byId('rememberUsername').checked) {
|
|
715
758
|
configuration.username = username;
|
|
716
759
|
configuration.password = password;
|
|
@@ -720,12 +763,7 @@
|
|
|
720
763
|
configuration.password = '';
|
|
721
764
|
}
|
|
722
765
|
|
|
723
|
-
await
|
|
724
|
-
homebridge.enableSaveButton();
|
|
725
|
-
|
|
726
|
-
await renderConfigForm(configuration, { hideDevices: true });
|
|
727
|
-
hideElement(byId('loginForm'));
|
|
728
|
-
showSaveNotice();
|
|
766
|
+
await applyRefreshToken(configuration, data.token);
|
|
729
767
|
btn.disabled = true;
|
|
730
768
|
btn.textContent = 'Get Token';
|
|
731
769
|
}
|
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.18",
|
|
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",
|