vojtamolda / homebridge-ecobee3-sensors

Homebridge plugin that exposes Ecobee 3 sensors as HomeKit accessories.
https://www.npmjs.com/package/homebridge-ecobee3-sensors
MIT License
26 stars 15 forks source link

One-time authorization code? #10

Closed flyingartichoke closed 7 years ago

flyingartichoke commented 7 years ago

Hello - I'm really enjoying this HomeBridge plugin!

There is one thing I am having issues with: having to re-enter a new authorization code every time I restart Homebridge (when I restart my computer, when the terminal crashes, power loss.. etc.). When I re-launch I get the following message:

[Ecobee] Token has been deauthorized by user. You must re-request authorization. Re-requesting authorization!

Is there any way to set this up as one-time authorization? I've already set-up Homebridge to start up again in any of these conditions, but since there is this authorization step the whole thing is hanging until I get a chance to update it in the ecobee portal.

Thanks!

vojtamolda commented 7 years ago

Hello @flyingartichoke,

thanks for enjoying the plugin and I apologize for your problems with re-authorization. The authorization should indeed persist between sessions and happen only once, so what you're seeing is certainly a bug.

My guess is that you are running Homebridge as a different user from the shell (i.e. your user account) and when it's running as a daemon (i.e root), right? This would cause trouble with authorization since the credentials are stored inside of the ~/.homebridge/ directory. For different users ~ resolves to different paths (i.e. /root/ and /home/$USER/).

The Ecobee authorization process allows every Ecobee account to authorize an app (i.e. this plugin) only once. New authorization under the same Ecobee account automatically revokes the previous authorization and makes the tokens stored in the other ~/.homebridge/ invalid. Invalid tokens trigger the re-authorization next time you start Homebridge. One way to fix this is to make one '~/.homebridge` a symbolic link to make sure you use the same config directory. You need to play with the permissions a bit also, since both users need write access to this dir.

It's only a guess, co I certainly might be wrong. If you see the problems when running under the same user, please, try to run homebridge -D and post the log here. This will print the requests/responses of the plugin to/from the Ecobee API servers, so I can see what's going on under the hood.

flyingartichoke commented 7 years ago

@vojtamolda - thanks so much for the suggestion! You were right, I was running the script from my user directory. I am now running it from the root directory and everything seems to be working correctly (no need to re-authenticate). Thanks again!

vojtamolda commented 7 years ago

Cool!