dhayab / homebridge-withings-air-quality

Homebridge plugin that exposes air quality data from the Withings WS-50 Smart Body Analyzer
MIT License
16 stars 6 forks source link

Plugin failure because of failing authentication #6

Closed tooh closed 3 years ago

tooh commented 4 years ago

Plugin was suddenly failing bringing down a lot of other plugins.

Logs indicate an unhandled exception. I went to the Withings portal and could not log in with my regular password.

I reset my password and reconfigured the plugin.

Plugin was working again.

Is it possible to improve the exception handling to clearly indicate the authentication failure?

TIA

tooh commented 4 years ago

Problem persists and seems to occur more often after installing latest version of homebridge

tooh commented 4 years ago

Pinpointed that the Withings password was again expired. Reset made it work again. Created an issue at Withings with request to investigate.

An expired password hangs other homebridge plugins. Would it be possible to improve and as such comply to the Verified guidelines? https://github.com/homebridge/verified

TIA

tooh commented 4 years ago

Reported issue to Withings support about the frequent expiry of the password.

Told Withings issue can be closed

Plugin is too instable for me to continue using it.

Below the info support asked to analyze issue.

In order to assist you with the issue, could you please provide us with the following information:

Partner app client_id (available here: https://account.withings.com/partner/dashboard_oauth2)

Partner app secret (available here: https://account.withings.com/partner/dashboard_oauth2)

Example of a failing call to Withings API:

URL called Parameters Date with the hour and timezone Response received from Withings API I will wait for your response.

Thank you and have a wonderful day!

Best regards,

dhayab commented 4 years ago

Hi, thanks for your report.

The plugin cannot use the official Withings OAuth2 API, as it exposes the temperature (type 12), but not the ppm levels (type 35).

This is why the plugin needs your Withings credentials, to access a legacy http endpoint used by the Withings web dashboard to display a graph of these values. To the best of my knowledge, there is no other way (as I don’t believe the ppm level will be added to the official API).

The problem with the legacy endpoint is that it is unstable and when it fails it only returns a generic error. When the plugin catches this error, it assumes it is because the session expired (it normally occurs ~ every 7 days). In that case the plugin starts a new session by authenticating again. If the error was not due to an expired session, the plugin keeps on connecting to the Withings server. If this happens a lot in a small timeframe, a security system kicks in and invalidates your Withings password.

Something could be done in the plugin to address this issue, for example disabling the plugin if the number of login attempts exceeds a set value in a set period. That said, I don’t have the ability to handle that currently. I’ll gladly accept a PR though, if you are (or someone else is) up to it.

martindinicolino commented 3 years ago

Hi, thanks for your report.

The plugin cannot use the official Withings OAuth2 API, as it exposes the temperature (type 12), but not the ppm levels (type 35).

This is why the plugin needs your Withings credentials, to access a legacy http endpoint used by the Withings web dashboard to display a graph of these values. To the best of my knowledge, there is no other way (as I don’t believe the ppm level will be added to the official API).

The problem with the legacy endpoint is that it is unstable and when it fails it only returns a generic error. When the plugin catches this error, it assumes it is because the session expired (it normally occurs ~ every 7 days). In that case the plugin starts a new session by authenticating again. If the error was not due to an expired session, the plugin keeps on connecting to the Withings server. If this happens a lot in a small timeframe, a security system kicks in and invalidates your Withings password.

Something could be done in the plugin to address this issue, for example disabling the plugin if the number of login attempts exceeds a set value in a set period. That said, I don’t have the ability to handle that currently. I’ll gladly accept a PR though, if you are (or someone else is) up to it.

Hey @dhayab please let me know what could be done to get this plugin to work again, I can't code but I'm willing to dump time in making this project work again, just point me in the right direction.

dhayab commented 3 years ago

Hi, thanks for your report. The plugin cannot use the official Withings OAuth2 API, as it exposes the temperature (type 12), but not the ppm levels (type 35). This is why the plugin needs your Withings credentials, to access a legacy http endpoint used by the Withings web dashboard to display a graph of these values. To the best of my knowledge, there is no other way (as I don’t believe the ppm level will be added to the official API). The problem with the legacy endpoint is that it is unstable and when it fails it only returns a generic error. When the plugin catches this error, it assumes it is because the session expired (it normally occurs ~ every 7 days). In that case the plugin starts a new session by authenticating again. If the error was not due to an expired session, the plugin keeps on connecting to the Withings server. If this happens a lot in a small timeframe, a security system kicks in and invalidates your Withings password. Something could be done in the plugin to address this issue, for example disabling the plugin if the number of login attempts exceeds a set value in a set period. That said, I don’t have the ability to handle that currently. I’ll gladly accept a PR though, if you are (or someone else is) up to it.

Hey @dhayab please let me know what could be done to get this plugin to work again, I can't code but I'm willing to dump time in making this project work again, just point me in the right direction.

Hi @martindinicolino , thanks for your interest in this plugin. Here are 2 things that could be done to make the plugin more stable:

They all require some familiarity with coding in general, and JavaScript / Node.js in particular though.

For the time being I'm closing this issue as it's been stale for a year, but feel free to create a new one if necessary.

martindinicolino commented 3 years ago

Hi, thanks for your report. The plugin cannot use the official Withings OAuth2 API, as it exposes the temperature (type 12), but not the ppm levels (type 35). This is why the plugin needs your Withings credentials, to access a legacy http endpoint used by the Withings web dashboard to display a graph of these values. To the best of my knowledge, there is no other way (as I don’t believe the ppm level will be added to the official API). The problem with the legacy endpoint is that it is unstable and when it fails it only returns a generic error. When the plugin catches this error, it assumes it is because the session expired (it normally occurs ~ every 7 days). In that case the plugin starts a new session by authenticating again. If the error was not due to an expired session, the plugin keeps on connecting to the Withings server. If this happens a lot in a small timeframe, a security system kicks in and invalidates your Withings password. Something could be done in the plugin to address this issue, for example disabling the plugin if the number of login attempts exceeds a set value in a set period. That said, I don’t have the ability to handle that currently. I’ll gladly accept a PR though, if you are (or someone else is) up to it.

Hey @dhayab please let me know what could be done to get this plugin to work again, I can't code but I'm willing to dump time in making this project work again, just point me in the right direction.

Hi @martindinicolino , thanks for your interest in this plugin. Here are 2 things that could be done to make the plugin more stable:

  • [ ] update the code to use the official Homebridge plugin template as a base
  • [ ] find a better way to handle session-related issues (cookies expiration, timeouts, etc.)

They all require some familiarity with coding in general, and JavaScript / Node.js in particular though.

For the time being I'm closing this issue as it's been stale for a year, but feel free to create a new one if necessary.

Thank you so much for replying, so you believe that working on the code for the plugin may prevent these issues from reoccurring?

Some were suggesting that the new Withings API is to blame 🤷‍♂️ - as i said before, i am a total noob, please let me know what you think.

I can‘t promise anything but i‘ll try reading up on JavaScript for this - any help is highly appreciated.