balansse / homebridge-vivint

Integrates Vivint security system with Apple Home
Other
45 stars 15 forks source link

Authentication works for a while - then starts failing #90

Closed ellucianBret closed 1 year ago

ellucianBret commented 1 year ago

Every few weeks I see this in the logs:

[Vivint] Error occured during login, retrying in 60 seconds... StatusCodeError: 401

BTW occurred is misspelled :) I only noticed because I use Grammarly - lol

The only resolution is to refresh the token. This is a new behavior. I don't remember having to refresh the token until a few months ago. The first time I had to reacquaint myself with this plugin. Which by the way means this is a well-done plugin :)

Did Vivint change their token expirations? Is there something I can do? Other than when this fails, go and manually refresh the token.

Thanks for a great plugin!

My config looks like this:

{
    "refreshToken": "s=my-vivint-refresh-token",
    "apiLoginRefreshSecs": 1200,
    "ignoreDeviceTypes": [
        "thermostat_device",
        "wireless_sensor"
    ],
    "useExternalVideoStreams": false,
    "platform": "Vivint"
}
jgrimard commented 1 year ago

I put in a pull request for the typo. That was probably my mistake. ;) Interesting that your token is expiring every 2 weeks. I wonder if it is something Vivint is pushing out? I haven't come across this issue myself. I haven't had to update my refresh token since setting it 6 months ago. Every time the plugin access the Vivint API, it extends the existing token expiration out a month. At least that is what is supposed to happen.

jgrimard commented 1 year ago

Something to check:

  1. Navigate to https://vivintsky.com/api/systems in a web browser like chrome. It should return "{"code": 401, "msg": "Your session has no user information. Please login", "msg_id": null}" That is the 401 error message your error refers to.
  2. Right click on the webpage and click Inspect. This will open DevTools.
  3. Click Application tab, then Cookies / httsp://vivintsky.com on the left.
  4. Right click below the __cf_bm cookie and click Add New to add a new cookie
  5. Name it s and set the Value to your latest working Vivint plugin cookie. (without the s= part)
  6. Go back to chrome and refresh the page. You should now see information about your vivint systems.
  7. Go back to DevTools and check the expiration date of your s cookie. It should be 1 month from today. If not maybe they changed something? Mine currently shows 1 month from today. 2022-12-27T17:26

Optional: If you want to see more information about your Vivint system from the Vivint API, you can copy and paste the id from the data returned to the URL. The new URL would look something like this: https://vivintsky.com/api/systems/1434020211493317 and navigate to it. This will return all of the information for your alarm panel including your address and GPS coordinates along with all your sensors and things. The data is JSON formatted, so to make it easier to read you could copy and paste it into a site like jsonformatter.io to view.

ellucianBret commented 1 year ago

I finally did this and the cookie is good for 1 month (30 days). I don't think my issue is with the plugin anymore. I am having to re-login to Vivint on my mobile devices too! My first indication is that notifications are delivered via SMS rather than push.

I'll bug Vivint support.

Thanks!