sychen52/nest-camera-site

Nest Authentication

Closed this issue · 28 comments

I have temporarily switched over to a separate Google account to test this application and it works great. However, I would like to switch back to my old nest account. Is there any chance the app will ever work with nest authentication?

I actually did not write the authentication part myself. I used Humpheh/nest-observe for its googe authentication as I acknowledged in the readme. I realize chrisjshull /
homebridge-nest has authentication for both nest and google. Which might be a good replacement for the current one I use. However, I don't have any plan to do it in the near future. I will add this to the projects tab though.

I understood that when I started using it. I had to create a new nest account to associate to a different Google account so I wouldn't have to migrate. It would be nice to swap back to using my main nest account for all my nest devices but get that you may not have the ability/time for developing something you don't need. I'll just stick with two accounts for now. Thanks!

I gave this a try and was greeted with the following:
Any ideas?

Server started on port 5000
(node:5070) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'split' of undefined
    at googleAuth (/Users/scott/Downloads/nest-camera-site/node_modules/nest-observe/auth.js:62:34)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:5070) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:5070) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

It would be neat to get it working with nest auth. Thanks for trying to get it working.

Did you try adding any of the command line arguments specified in the output?

No I have tried to add them. I will try to and report back.

What part of the .split does it not like?

At one time, I had a Nest Developer's account and had all of the tokens, etc but, I have no copies of any of them and there seems to be no way to retrieve them now.

Changed computers and using a Debian 10 based (MX-Linux) and have attached the log file.
2020-06-14T20_56_38_302Z-debug.log

@kkuhle I just switch to homebridge-nest for authentication. Technically, it should support nest accounts. Could you follow the instruction on homebridge-nest to test?

Awesome! I was trying to set it up again using Google auth a few nights ago before I left town for a few days, but I couldn't get it to work. Initially, the app loaded, but I forgot to get the camera uuid and after I for some reason invalidated my creds and couldn't get it to work again. I'll see if I can attempt it tonight.

You don't need to have homekit.

@sychen52 I downloaded the new version and can't seem to get it to work. Here is my config:

image

  • Create key pair:
$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./selfsigned.key -out ./selfsigned.crt
Can't load /home/kkuhle/.rnd into RNG
139937850528192:error:2406F079:random number generator:RAND_load_file:Cannot open file:../crypto/rand/randfile.c:88:Filename=/home/kkuhle/.rnd
Generating a RSA private key
....+++++
....................................................................+++++
writing new private key to './selfsigned.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:
  • Install
$ npm install
npm WARN deprecated crypto@1.0.1: This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in.
npm WARN deprecated request-promise@4.2.6: request-promise has been deprecated because it extends the now deprecated request package, see https://github.com/request/request/issues/3142
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated

> nodemon@1.19.4 postinstall /raid/scripts/nest-camera-site/node_modules/nodemon
> node bin/postinstall || exit 0

nest-camera-site@1.0.0 /raid/scripts/nest-camera-site
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.2.13
npm WARN nest-camera-site@1.0.0 No repository field.
  • start
$ npm run start

> nest-camera-site@1.0.0 start /raid/scripts/nest-camera-site
> node index

/raid/scripts/nest-camera-site/utils.js:24
    log = console.log;
        ^

SyntaxError: Unexpected token =
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/raid/scripts/nest-camera-site/capture.js:1:88)

npm ERR! Linux 4.15.0-99-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "run" "start"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! nest-camera-site@1.0.0 start: `node index`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nest-camera-site@1.0.0 start script 'node index'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the nest-camera-site package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node index
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs nest-camera-site
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls nest-camera-site
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /raid/scripts/nest-camera-site/npm-debug.log
  • debug log
$ cat npm-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'run', 'start' ]
2 info using npm@3.5.2
3 info using node@v8.10.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle nest-camera-site@1.0.0~prestart: nest-camera-site@1.0.0
6 silly lifecycle nest-camera-site@1.0.0~prestart: no script for prestart, continuing
7 info lifecycle nest-camera-site@1.0.0~start: nest-camera-site@1.0.0
8 verbose lifecycle nest-camera-site@1.0.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle nest-camera-site@1.0.0~start: PATH: /usr/share/npm/bin/node-gyp-bin:/raid/scripts/nest-camera-site/node_modules/.bin:/home/kkuhle/.local/bin:/home/kkuhle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
10 verbose lifecycle nest-camera-site@1.0.0~start: CWD: /raid/scripts/nest-camera-site
11 silly lifecycle nest-camera-site@1.0.0~start: Args: [ '-c', 'node index' ]
12 silly lifecycle nest-camera-site@1.0.0~start: Returned: code: 1  signal: null
13 info lifecycle nest-camera-site@1.0.0~start: Failed to exec start script
14 verbose stack Error: nest-camera-site@1.0.0 start: `node index`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/usr/share/npm/lib/utils/lifecycle.js:232:16)
14 verbose stack     at emitTwo (events.js:126:13)
14 verbose stack     at EventEmitter.emit (events.js:214:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/share/npm/lib/utils/spawn.js:24:14)
14 verbose stack     at emitTwo (events.js:126:13)
14 verbose stack     at ChildProcess.emit (events.js:214:7)
14 verbose stack     at maybeClose (internal/child_process.js:925:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
15 verbose pkgid nest-camera-site@1.0.0
16 verbose cwd /raid/scripts/nest-camera-site
17 error Linux 4.15.0-99-generic
18 error argv "/usr/bin/node" "/usr/bin/npm" "run" "start"
19 error node v8.10.0
20 error npm  v3.5.2
21 error code ELIFECYCLE
22 error nest-camera-site@1.0.0 start: `node index`
22 error Exit status 1
23 error Failed at the nest-camera-site@1.0.0 start script 'node index'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the nest-camera-site package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error     node index
23 error You can get information on how to open an issue for this project with:
23 error     npm bugs nest-camera-site
23 error Or if that isn't available, you can get their info via:
23 error     npm owner ls nest-camera-site
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]\

Thanks a lot for testing and send me the log. I noticed that you are using node 8. Is it easy for you to upgrade your nodejs. If not, I need to change my code to use the old style.

No worries. Thanks for working on this.

  • Updated:
$ node -v
v12.18.3
  • Maybe still not a good version?
$ npm install

> nodemon@1.19.2 postinstall /raid/scripts/nest-camera-site/node_modules/nodemon
> node bin/postinstall || exit 0

npm WARN nest-camera-site@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.12 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.12: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 3 packages from 4 contributors, removed 3 packages, updated 18 packages and audited 474 packages in 3.235s

2 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

$ npm fund
nest-camera-site@1.0.0
├─┬ https://github.com/sponsors/epoberezkin
│ └── ajv@6.12.3
└─┬ https://github.com/sponsors/isaacs
  └── glob@7.1.6

$ npm run start

> nest-camera-site@1.0.0 start /raid/scripts/nest-camera-site
> node index

Server started on port 5000
undefined:7
        }
        ^

SyntaxError: Unexpected token } in JSON at position 284
    at JSON.parse (<anonymous>)
    at /raid/scripts/nest-camera-site/capture.js:17:29
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nest-camera-site@1.0.0 start: `node index`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nest-camera-site@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/kkuhle/.npm/_logs/2020-08-19T18_54_51_327Z-debug.log
  • check log
$ cat npm-debug.log
$
$ cat /home/kkuhle/.npm/_logs/2020-08-19T18_54_51_327Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/home/kkuhle/.nvm/versions/node/v12.18.3/bin/node',
1 verbose cli   '/home/kkuhle/.nvm/versions/node/v12.18.3/bin/npm',
1 verbose cli   'run',
1 verbose cli   'start'
1 verbose cli ]
2 info using npm@6.14.6
3 info using node@v12.18.3
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle nest-camera-site@1.0.0~prestart: nest-camera-site@1.0.0
6 info lifecycle nest-camera-site@1.0.0~start: nest-camera-site@1.0.0
7 verbose lifecycle nest-camera-site@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle nest-camera-site@1.0.0~start: PATH: /home/kkuhle/.nvm/versions/node/v12.18.3/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/raid/scripts/nest-camera-site/node_modules/.bin:/home/kkuhle/.nvm/versions/node/v12.18.3/bin:/home/kkuhle/.local/bin:/home/kkuhle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle nest-camera-site@1.0.0~start: CWD: /raid/scripts/nest-camera-site
10 silly lifecycle nest-camera-site@1.0.0~start: Args: [ '-c', 'node index' ]
11 silly lifecycle nest-camera-site@1.0.0~start: Returned: code: 1  signal: null
12 info lifecycle nest-camera-site@1.0.0~start: Failed to exec start script
13 verbose stack Error: nest-camera-site@1.0.0 start: `node index`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/home/kkuhle/.nvm/versions/node/v12.18.3/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (/home/kkuhle/.nvm/versions/node/v12.18.3/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid nest-camera-site@1.0.0
15 verbose cwd /raid/scripts/nest-camera-site
16 verbose Linux 4.15.0-99-generic
17 verbose argv "/home/kkuhle/.nvm/versions/node/v12.18.3/bin/node" "/home/kkuhle/.nvm/versions/node/v12.18.3/bin/npm" "run" "start"
18 verbose node v12.18.3
19 verbose npm  v6.14.6
20 error code ELIFECYCLE
21 error errno 1
22 error nest-camera-site@1.0.0 start: `node index`
22 error Exit status 1
23 error Failed at the nest-camera-site@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

What version are you on?

This version is good enough. Let me look into the log.

@sychen52 silly me had an extra } which I realized when I read the output.

  • Seems like progress?
$ npm run start

> nest-camera-site@1.0.0 start /raid/scripts/nest-camera-site
> node index

Server started on port 5000
Authenticating via access token.
2020-08-19T19:06:23.838Z 403
Authenticating via access token.
2020-08-19T19:06:26.529Z 403
Authenticating via access token.
2020-08-19T19:06:29.134Z 403
Authenticating via access token.

I had this working at one point. Are images supposed to be logged to the nest folder? The output provided above seems to continue indefinitely, so I'm not sure if authentication is not working or what.

Yes. It is trying at least. Let me look into it and maybe add more log. I probably will ask you to try again later.

Sounds good. With the API access_token obtained using https://github.com/chrisjshull/homebridge-nest#configuration I get the response detailed above. If I intentionally mess up the API access_token, then I see:

$ npm run start

> nest-camera-site@1.0.0 start /raid/scripts/nest-camera-site
> node index

Server started on port 5000
Authenticating via access token.
Auth failed: access token specified in Homebridge configuration rejected
Unable to connect to Nest service.
2020-08-19T19:21:52.159Z 400
Authenticating via access token.
Auth failed: access token specified in Homebridge configuration rejected
Unable to connect to Nest service.
2020-08-19T19:21:53.947Z 400
Authenticating via access token.
Auth failed: access token specified in Homebridge configuration rejected
Unable to connect to Nest service.
2020-08-19T19:21:55.740Z 400
Authenticating via access token.
Auth failed: access token specified in Homebridge configuration rejected
Unable to connect to Nest service.
2020-08-19T19:21:57.585Z 400
Authenticating via access token.
Auth failed: access token specified in Homebridge configuration rejected
Unable to connect to Nest service.

So it would seem the creds are good at least!

Looks promising. When you get your camera uuid, can you check whether the url is something like this:

https://nexusapi-${config['server']}.camera.home.nest.com/get_image?uuid=${config['uuid']}&width=${config['resolution']}

Actually, if you followed this part of the instruction to get the uuid, Do you mind share you url (get rid of the uuid part).

uuid is the camera uuid you would like to capture. Similar to the instruction linked above, expect that you need to Filter for get_image. The string after uuid= and before & is your camera uuid.

The URL in the DevTools is https://nexusapi-us1.camera.home.nest.com/get_image?uuid=16&cachebuster=1597894116873

Is this what you're talking about? I am using the uuid part as the instructions indicate:

image

The URL you provided seems to be the URL configured in the app. Is there a way to verify that the URL is being formatted properly?

Looks the same. Let me check something else. Just to make sure one more thing. You said this worked for you before when you used google account, right? Or is this the first time you run this?

Yes, I had it working with a Google account. I removed the camera from my Google account today and back to my Nest account. If I remove the uuid line, I get a bad request. With it, I get forbidden?

kkuhle@kuhlenas:/scripts/nest-camera-site$ npm run start

> nest-camera-site@1.0.0 start /raid/scripts/nest-camera-site
> node index

Server started on port 5000
Authenticating via access token.
2020-08-20T03:32:18.794Z 403
Authenticating via access token.
2020-08-20T03:32:21.443Z 403
Authenticating via access token.
2020-08-20T03:32:23.926Z 403
Authenticating via access token.
^C
kkuhle@kuhlenas:/scripts/nest-camera-site$ vi config.json
kkuhle@kuhlenas:/scripts/nest-camera-site$ npm run start

> nest-camera-site@1.0.0 start /raid/scripts/nest-camera-site
> node index

Server started on port 5000
Authenticating via access token.
2020-08-20T03:57:10.056Z 400
Authenticating via access token.
2020-08-20T03:57:12.530Z 400
Authenticating via access token.
2020-08-20T03:57:15.020Z 400
Authenticating via access token.

Got it. Thanks a lot. Let me try something else.

FWIW, I can go directly to https://nexusapi-us1.camera.home.nest.com/get_image?uuid=1[omit]6&width=1920 and I get an image.

if I modify the fetch(.* in the capture.js file, to the above URL, I still receive 403 response when starting the app. 400 response if I mess up the uuid.

When I use google account, the access_token expires every hour or so. And when it expires, I get a 403. So I just re-run the authentication to get the access_token again. It seems very different for nest account. You directly get the access_token. Maybe this access_token won't expire, but I am not sure.
I just added a console.log of the 403 response. Not sure whether that response can tell us why it gets forbidden. Anyway, thank you again for testing. I do not have a nest account, so it is pretty hard to figure out what happened.

I have Homebridge up and running on a Debian 10 base system. Have the Homebridge Nest Cam plug in installed and added my credentials to the config file as per chrisjshull's posts. The screen shows that it recognises a device called Driveway, but I don't see any video.

I have updated the homebridge in the dependency. whatever authentication they support, this module should support as well.
998629f