core: Withings Integration fails to renew Oauth, Cannot request new Oauth token - integration dead.

The problem

Withings Integration fails to renew OAuth, cannot request new OAuth token - integration dead.

Starting two days ago one of my two users of the Withings integration stopped working, with failed to setup messages in the dashboard. Normal tricks to reconnect also failed (usually this fails because Im logged into the wrong ‘face’ of HA - im on my public NabuCasa url instead of the internal IP interface or vice versa - so I just relog and start over and it fixes it…)

This time it did not. I looked at HA for breakages - saw none, checked my other ID and it still worked. Until it didn’t - it stopped reporting about an hour later. ( I always renew these together - this is not surprising at all.)

SO, I completely DELETED one of my integrations, and restarted HA to ensure it and its entities were gone. After Restart Attempted to add the integration fails. Normal flow through the OAuth challenge and you are correctly passed to Withing’s to Auth - who then passes to the HA screen confirming the link (why the URL is not the issue - you’d fail before here; it wouldn’t know where to send you - I used to be an Active Directory engineer) It pops the user back to what would normally be the confirmation screen - and it clocks with the wait circle.

OAuth eventually times out and you get a blank dialog with no text and an OK button.

Clicking OK returns, you to the dashboard without adding the integration

ONLY evidence in the log is:

Logger: homeassistant.helpers.config_entry_oauth2_flow Source: helpers/config_entry_oauth2_flow.py:318 First occurred: September 14, 2023 at 11:16:30 PM (3 occurrences) Last logged: September 14, 2023 at 11:21:50 PM

Timeout resolving OAuth token:

This timeout aligns with the time when I attempted to re-add 3 occurrences align with the fact I retried it 3 times. 😃

It’s definitely that.

What version of Home Assistant Core has the issue?

2023.9.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

withings

Link to integration documentation on our website

https://www.home-assistant.io/integrations/withings/

Diagnostics information

Unavailable - integration wont install

Example YAML snippet

n/a

Anything in the logs that might be useful for us?

Logger: homeassistant.helpers.config_entry_oauth2_flow
Source: helpers/config_entry_oauth2_flow.py:318
First occurred: September 14, 2023 at 11:16:30 PM (3 occurrences)
Last logged: September 14, 2023 at 11:21:50 PM

Timeout resolving OAuth token:

Additional information

Was a working install with two known good users until token timed out. Looks like auth changed somehow,

There is a new-ish? button on the Withings dev portal - where you setup the App (BTW docs are out of date - doesn’t match the UI anymore, big suprise) to test each of the links. they always fail. I suspect once we’re meeting whatever requirements they added it wont fail anymore. but I dont have access to the right tooling at the moment to see all the comms - and the delta between what they’re asking and we’re responding or not responding with in kind…

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Reactions: 1
  • Comments: 15 (9 by maintainers)

Most upvoted comments

No thanks, this is a productive system. I wait for 2023.10 when this fixes the problem.

I can offer log support but all the tunnels I use to connect are encrypted - so no traces, sorry.

For repro purposes, I have two Withings Accounts. The withings side app on the dev portal is setup in my account which we will call A. I also have a second account which we will call B (the partner / SO account)

When all is connected/setup correctly A owns the withings side App The app was setup with correct urls for BOTH a nabu casa install (listed first) and the HA Oauth default url (listed second, added as additional) Two integrations get setup - A’s Integration logs in through A’s Oauth App using A’s credentials to access A’s data B’s Integration logs in through A’s Oauth App using B’s credentials to access B’s data (Yes this works and has for over a year)

For repro purposes, we’re IGNORING B’s use case and looking at A’s only.

I’ll try to debug this in a bit, have the new version running on my production environment already

as a matter of fact, previously the use_webhook setting was only read when you initially set up Withings. So if it was false (or not set) before and you then set it to True, it doesn’t apply iirc. This will be all history in 2023.10 😃

2023.10 would have the rework. Beta would be dropping next week on wednesday, release the week after

In my installation I see the same problem. Oauth failes with timeout error in the GUI. In the log is written:

2023-09-16 14:13:37.075 ERROR (MainThread) [homeassistant.components.withings] Unexpected error fetching subscription_update_coordinator data: Error code 401
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 293, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 248, in _async_update_data
    return await self.update_method()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 321, in async_subscribe_webhook
    return await self._do_retry(self._async_subscribe_webhook)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 317, in _do_retry
    raise exception
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 306, in _do_retry
    return await func()
           ^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 332, in _async_subscribe_webhook
    await self.async_unsubscribe_webhook()
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 369, in async_unsubscribe_webhook
    return await self._do_retry(self._async_unsubscribe_webhook)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 317, in _do_retry
    raise exception
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 306, in _do_retry
    return await func()
           ^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/withings/common.py", line 373, in _async_unsubscribe_webhook
    response = await self._hass.async_add_executor_job(self._api.notify_list)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/withings_api/__init__.py", line 315, in notify_list
    return NotifyListResponse(**self.request(path=self.PATH_NOTIFY, params=params))
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/withings_api/__init__.py", line 115, in request
    return response_body_or_raise(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/withings_api/common.py", line 828, in response_body_or_raise
    raise AuthFailedException(status=status)
withings_api.common.AuthFailedException: Error code 401

Of course this worked before. The integration just says it needs a re-authentication and then this happens on the last step.