home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.34k stars 29.88k forks source link

Bad Request / HTTP 400 when starting up the Xbox integration #61046

Closed deviantintegral closed 2 years ago

deviantintegral commented 2 years ago

The problem

The Xbox integration is throwing this error when starting up:

aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url=URL('https://account-link.nabucasa.com/refresh_token/xbox')

What's unclear is if this a 400 being issued by Nabu Casa, or a 400 from the Xbox API being passed through. If this is some issue related to credentials, the integration isn't offering me a chance to reauthenticate.

What version of Home Assistant Core has the issue?

core-2021.11.5

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

Xbox

Link to integration documentation on our website

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

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 304, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/xbox/__init__.py", line 89, in async_setup_entry
    consoles: SmartglassConsoleList = await client.smartglass.get_console_list()
  File "/usr/local/lib/python3.9/site-packages/xbox/webapi/api/provider/smartglass/__init__.py", line 54, in get_console_list
    resp = await self._fetch_list("devices", params, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/xbox/webapi/api/provider/smartglass/__init__.py", line 359, in _fetch_list
    resp = await self.client.session.get(
  File "/usr/local/lib/python3.9/site-packages/xbox/webapi/api/client.py", line 86, in get
    return await self.request(hdrs.METH_GET, url, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/xbox/webapi/api/client.py", line 60, in request
    await self._auth_mgr.refresh_tokens()
  File "/usr/src/homeassistant/homeassistant/components/xbox/api.py", line 27, in refresh_tokens
    await self._oauth_session.async_ensure_token_valid()
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 461, in async_ensure_token_valid
    new_token = await self.implementation.async_refresh_token(self.token)
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 88, in async_refresh_token
    new_token = await self._async_refresh_token(token)
  File "/usr/src/homeassistant/homeassistant/components/cloud/account_link.py", line 116, in _async_refresh_token
    new_token = await account_link.async_fetch_access_token(
  File "/usr/local/lib/python3.9/site-packages/hass_nabucasa/account_link.py", line 112, in async_fetch_access_token
    resp.raise_for_status()
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1000, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url=URL('https://account-link.nabucasa.com/refresh_token/xbox')

Additional information

No response

probot-home-assistant[bot] commented 2 years ago

Hey there @hunterjm, mind taking a look at this issue as it has been labeled with an integration (xbox) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)


xbox documentation xbox source (message by IssueLinks)

deviantintegral commented 2 years ago

This is still an issue in 2021.12.0b4.

eavanvalkenburg commented 2 years ago

Same here!

honkerst commented 2 years ago

I've started experiencing this error too, and I don't use Nabu Casa.

deviantintegral commented 2 years ago

No improvements so far.

If I had to guess, the team at Nabu Casa are operating a proxy to allow for OAuth to work easily and that this is used regardless of a subscription to their service.

A simple GET to https://account-link.nabucasa.com/refresh_token/xbox gives me a 404. That could be expected, if they are returning all 403s as 404s to mask what paths exist and don't exist.

A 400 would indicate that something is wrong with the integration, but it doesn't look like there's an easy way to get the request logged to investigate: https://github.com/NabuCasa/hass-nabucasa/blob/f48664aa1ecaac73986b38dc8c0e7a97ab1e99eb/hass_nabucasa/account_link.py#L105-L115

It would certainly be faster if someone at Nabu Casa could check the server logs and see if that says why it's being rejected.

Has anyone tried removing and re-adding the integration?

milkywayfarer commented 2 years ago

Can confirm this is still an issue in 2022.2.0. Things that did not help:

Other functions besides turning the console on are working as expected.

This actually might be the problem on the Xbox side, because my Xbox Android app does not turn on the console too.

deviantintegral commented 2 years ago

I re-added the integration yesterday and it seemed to work. Anyone else?

eavanvalkenburg commented 2 years ago

Was fixed for me when Brunt was fixed