mirror of
https://github.com/koush/scrypted.git
synced 2026-09-19 10:10:39 +01:00
google-home: fix local auth
This commit is contained in:
2
plugins/google-home/.vscode/settings.json
vendored
2
plugins/google-home/.vscode/settings.json
vendored
@@ -1,4 +1,4 @@
|
||||
|
||||
{
|
||||
"scrypted.debugHost": "127.0.0.1",
|
||||
"scrypted.debugHost": "koushik-ubuntu",
|
||||
}
|
||||
@@ -71,6 +71,10 @@ app
|
||||
|
||||
command.data = JSON.stringify(request);
|
||||
|
||||
command.additionalHeaders = {
|
||||
'Authorization': (request.inputs?.[0]?.payload?.devices?.[0]?.customData as any)?.localAuthorization,
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await app.getDeviceManager()
|
||||
.send(command);
|
||||
@@ -109,6 +113,10 @@ app
|
||||
|
||||
command.data = JSON.stringify(request);
|
||||
|
||||
command.additionalHeaders = {
|
||||
'Authorization': (request.inputs?.[0]?.payload?.commands?.[0].devices?.[0]?.customData as any)?.localAuthorization,
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await app.getDeviceManager()
|
||||
.send(command);
|
||||
|
||||
4
plugins/google-home/package-lock.json
generated
4
plugins/google-home/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/google-home",
|
||||
"version": "0.0.50",
|
||||
"version": "0.0.51",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/google-home",
|
||||
"version": "0.0.50",
|
||||
"version": "0.0.51",
|
||||
"dependencies": {
|
||||
"@googleapis/homegraph": "^2.0.0",
|
||||
"@homebridge/ciao": "^1.1.5",
|
||||
|
||||
@@ -48,5 +48,5 @@
|
||||
"@types/lodash": "^4.14.168",
|
||||
"@types/url-parse": "^1.4.3"
|
||||
},
|
||||
"version": "0.0.50"
|
||||
"version": "0.0.51"
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ const includeToken = 3;
|
||||
class GoogleHome extends ScryptedDeviceBase implements HttpRequestHandler, EngineIOHandler, MixinProvider {
|
||||
linkTracker = localStorage.getItem('linkTracker');
|
||||
agentUserId = localStorage.getItem('agentUserId');
|
||||
localAuthorization = localStorage.getItem('localAuthorization');
|
||||
reportQueue = new Set<string>();
|
||||
reportStateThrottled = throttle(() => this.reportState(), 2000);
|
||||
throttleSync = throttle(() => this.requestSync(), 15000, {
|
||||
@@ -83,6 +84,11 @@ class GoogleHome extends ScryptedDeviceBase implements HttpRequestHandler, Engin
|
||||
localStorage.setItem('agentUserId', this.agentUserId);
|
||||
}
|
||||
|
||||
if (!this.localAuthorization) {
|
||||
this.localAuthorization = uuidv4();
|
||||
localStorage.setItem('localAuthorization', this.localAuthorization);
|
||||
}
|
||||
|
||||
try {
|
||||
this.defaultIncluded = JSON.parse(localStorage.getItem('defaultIncluded'));
|
||||
}
|
||||
@@ -247,6 +253,9 @@ class GoogleHome extends ScryptedDeviceBase implements HttpRequestHandler, Engin
|
||||
|
||||
const probe = await supportedType.getSyncResponse(device);
|
||||
|
||||
probe.customData = {
|
||||
'localAuthorization': this.localAuthorization,
|
||||
};
|
||||
probe.roomHint = device.room;
|
||||
probe.notificationSupportedByAgent = true;
|
||||
ret.payload.devices.push(probe);
|
||||
@@ -507,21 +516,23 @@ class GoogleHome extends ScryptedDeviceBase implements HttpRequestHandler, Engin
|
||||
}
|
||||
|
||||
const { authorization } = request.headers;
|
||||
if (!this.validAuths.has(authorization)) {
|
||||
try {
|
||||
await axios.get('https://home.scrypted.app/_punch/getcookie', {
|
||||
headers: {
|
||||
'Authorization': authorization,
|
||||
}
|
||||
});
|
||||
this.validAuths.add(authorization);
|
||||
}
|
||||
catch (e) {
|
||||
this.console.error(`request failed due to invalid authorization`, e);
|
||||
response.send(e.message, {
|
||||
code: 500,
|
||||
});
|
||||
return;
|
||||
if (authorization !== this.localAuthorization) {
|
||||
if (!this.validAuths.has(authorization)) {
|
||||
try {
|
||||
await axios.get('https://home.scrypted.app/_punch/getcookie', {
|
||||
headers: {
|
||||
'Authorization': authorization,
|
||||
}
|
||||
});
|
||||
this.validAuths.add(authorization);
|
||||
}
|
||||
catch (e) {
|
||||
this.console.error(`request failed due to invalid authorization`, e);
|
||||
response.send(e.message, {
|
||||
code: 500,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user