wylanswets / homebridge-icontrol-platform

Enables iControl home security systems and other accessories in Homebridge for homekit
4 stars 2 forks source link

Update: Refresh token issue and resolution #13

Closed twadef closed 3 years ago

twadef commented 3 years ago

I used the proxy and could find a refresh_token key, but I found a refreshTokens key. If I put a different value in as the refresh token, I get an error code that simply says it isn't correct. When I put that value in, I get the following lines of error code:

There was an error while communicating with iControl. Status code was 500 and error was: Error: Invalid status code 500 at iControl.<anonymous> (/usr/local/lib/node_modules/homebridge-icontrol-platform/node_modules/icontrol-api/index.js:359:20) at Request.self.callback (/usr/local/lib/node_modules/homebridge-icontrol-platform/node_modules/request/request.js:185:22) at Request.emit (events.js:314:20) at Request.<anonymous> (/usr/local/lib/node_modules/homebridge-icontrol-platform/node_modules/request/request.js:1154:10) at Request.emit (events.js:314:20) at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/homebridge-icontrol-platform/node_modules/request/request.js:1076:12) at Object.onceWrapper (events.js:420:28) at IncomingMessage.emit (events.js:326:22) at endReadableNT (_stream_readable.js:1223:12) at processTicksAndRejections (internal/process/task_queues.js:84:21) Stack:Error: at iControl._notifyError (/usr/local/lib/node_modules/homebridge-icontrol-platform/node_modules/icontrol-api/index.js:505:181) at iControl.<anonymous> (/usr/local/lib/node_modules/homebridge-icontrol-platform/node_modules/icontrol-api/index.js:360:12) at Request.self.callback (/usr/local/lib/node_modules/homebridge-icontrol-platform/node_modules/request/request.js:185:22) at Request.emit (events.js:314:20) at Request.<anonymous> (/usr/local/lib/node_modules/homebridge-icontrol-platform/node_modules/request/request.js:1154:10) at Request.emit (events.js:314:20) at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/homebridge-icontrol-platform/node_modules/request/request.js:1076:12) at Object.onceWrapper (events.js:420:28) at IncomingMessage.emit (events.js:326:22) at endReadableNT (_stream_readable.js:1223:12) at processTicksAndRejections (internal/process/task_queues.js:84:21) Response: {"error":"server_error","error_description":"AuthorizationGrantDTO[user_id]; no HASH key value present"}

Any ideas on how to resolve from here?

Edit: After playing around some more, I realize this is what I get when I put the wrong refresh_token value. What I get when I copy and paste it is this:

{"error":"invalid_grant","error_description":"Invalid refresh token: <Access Token>"}

twadef commented 3 years ago

I think I've managed to solve the problem and why a) I wasn't finding a refresh_token key (and just refreshTokens), and b) why the value I was using was invalid. Here are a few things to keep in mind:

  1. The login form allows you to use a username or an email address. I'm not sure what all goes into the hash, but switching the app login from my username to my e-mail address seems to have helped. Make sure you're entering the same credentials in the app that you're using in this plugin.

  2. The access token will live for at least 5 minutes before it needs to be refreshed. Closing at the app for at least 5 minutes (I let it go for over an hour) will necessitate a need for a refresh token to get a new access token. Once I let it sit, when I ran the app again, I immediately got the refresh_token key I was looking for.

Doing that gave me a refresh_token value that works, and I know have the system loaded into Homebridge. Thanks for putting this together!

wylanswets commented 3 years ago

@twadef I'm glad you got it resolved! Yes... and for future reference you might be able to speed that up by deleting and re-installing the app ;)

twadef commented 3 years ago

I deleted and reinstalled the app too many times to count during the process. 😂 That’s why my last ditch attempt was to let it sit long enough for the original access token to expire, and try to force passing the refresh_token key that way. I’m not sure why the value in the refreshTokens key didn’t work.

Also, now that it’s up and running...when I try to use the system as a trigger for automations in the Home app, I only have the option to trigger when the system is armed generally, and not armed by a specific state. What I would like is to shut off lights and outlets, lock the doors, and set my Ecobee into away mode when the Xfinity system arms Away (but not in Home or Night modes). Is this functionality you’ve looked at adding, or any way I can do that through config file?