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.73k stars 29.98k forks source link

Unable to add Twitch Integration #102011

Closed DigitalFeonix closed 5 months ago

DigitalFeonix commented 11 months ago

The problem

When trying to add the Twitch integration, the config flow does not seem to work.

Had the integration added previous to 2023.10.x and was working. Upon release of 2023.10.0 my attempts to upgrade failed. I had removed the YAML sensor after upgrading to 2023.10.0 and restarted, but it failed. I removed TWO "devices" from the integration (when I only had ONE with the old method) in an attempt to do a clean addition. This was done before I saw the information about updating the OAuth Redirect URL. Further attempts to add it have failed.

2023.10.0 and 2023.10.1 resulted in errors the seemed to be coming from the aiohttp package so I tried to use my external address with my.home-assistant.io thinking that it might not like HTTP and required a HTTPS with no change.

What version of Home Assistant Core has the issue?

core-2023.10.3

What was the last working version of Home Assistant Core?

core-2023.9.x

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Twitch

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Log from 2023.10.2 (tokens altered)
2023-10-14 12:28:05.109 WARNING (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Invalid token: {'access_token': 'b4wkqjz6yo47jk1ppw9n2dvl6z7wg3', 'refresh_token': '3fe2rvbnqm14i3s6ttnqt3s32uasiq44ovb7ialqeu38v6pn9v', 'scope': ['user:read:follows', 'user:read:subscriptions'], 'token_type': 'bearer'}

Log from 2023.10.3 (tokens altered)
2023-10-14 12:34:39.307 WARNING (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Invalid token: {'access_token': 'j44hgtqdppzgvyfsnyigqtebkrqlvr', 'refresh_token': 'elwgtc0ixi3zzw0aksdab4fp2cyjz9k04nm5ioy1r9dm96l8a0', 'scope': ['user:read:follows', 'user:read:subscriptions'], 'token_type': 'bearer'}

Additional information

Only app in Twitch Dev Console. ha-twitch4

The results of trying to add Twitch with 2023.10.2 and 2023.10.3 ha-twitch1 ha-twitch2 ha-twitch3

2023.10.0 and 2023.10.1 looked the same except the last screen which said "Error" instead of "Twitch"

home-assistant[bot] commented 11 months ago

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

Code owner commands Code owners of `twitch` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign twitch` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


twitch documentation twitch source (message by IssueLinks)

joostlek commented 11 months ago

anything in the logs?

DigitalFeonix commented 11 months ago

Just the "Invalid token" lines that I attached to the original post

Log from 2023.10.2 (tokens altered) 2023-10-14 12:28:05.109 WARNING (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Invalid token: {'access_token': 'b4wkqjz6yo47jk1ppw9n2dvl6z7wg3', 'refresh_token': '3fe2rvbnqm14i3s6ttnqt3s32uasiq44ovb7ialqeu38v6pn9v', 'scope': ['user:read:follows', 'user:read:subscriptions'], 'token_type': 'bearer'}

Log from 2023.10.3 (tokens altered) 2023-10-14 12:34:39.307 WARNING (MainThread) [homeassistant.helpers.config_entry_oauth2_flow] Invalid token: {'access_token': 'j44hgtqdppzgvyfsnyigqtebkrqlvr', 'refresh_token': 'elwgtc0ixi3zzw0aksdab4fp2cyjz9k04nm5ioy1r9dm96l8a0', 'scope': ['user:read:follows', 'user:read:subscriptions'], 'token_type': 'bearer'}

joostlek commented 11 months ago

Oh right, overlooked.

I introduced this check in core in #101642, since this was failing in Withings. (And looking at the code, it would've failed anyway). I am curious why this now happens. I'll try to find some time to try to reproduce this and come back with some resutls.

StellarTransmissions commented 11 months ago

I think this is the same issue

Here are my log if it is any help to you

Logger: aiohttp.server
Source: /usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py:403
First occurred: 10:29:37 (1 occurrences)
Last logged: 10:29:37

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 227, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 63, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 170, in get
    return await super().get(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 96, in get
    result = await self._flow_mgr.async_configure(flow_id)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 293, in async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 394, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 314, in async_step_creation
    token = await self.flow_impl.async_resolve_external_data(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 171, in async_resolve_external_data
    return await self._token_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 208, in _token_request
    resp.raise_for_status()
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 1005, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 403, message='Forbidden', url=URL('https://id.twitch.tv/oauth2/token')
DigitalFeonix commented 11 months ago

I think this is the same issue

Here are my log if it is any help to you

Logger: aiohttp.server
Source: /usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py:403
First occurred: 10:29:37 (1 occurrences)
Last logged: 10:29:37

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 227, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 148, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 63, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 170, in get
    return await super().get(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 96, in get
    result = await self._flow_mgr.async_configure(flow_id)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 293, in async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 394, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 314, in async_step_creation
    token = await self.flow_impl.async_resolve_external_data(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 171, in async_resolve_external_data
    return await self._token_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 208, in _token_request
    resp.raise_for_status()
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 1005, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 403, message='Forbidden', url=URL('https://id.twitch.tv/oauth2/token')

That looks similar to what I saw with 2023.10.0 and 2023.10.1, and the reason I tried my external HTTPS address in addition to my internal HTTP one, but unfortunately I did not save a copy of the log.

gohm44 commented 10 months ago

I had a similar issue. In my case, I found that there were some old credentials for twitch (from yaml) in homeassistant.local/config/application_credentials After remove, working fine

image

StellarTransmissions commented 10 months ago

I had a similar issue. In my case, I found that there were some old credentials for twitch (from yaml) in homeassistant.local/config/application_credentials After remove, working fine

image

thank you so much. worked like a treat, fixed

schmittey commented 10 months ago

deleting the old twitch entry from application_credentials did fix it for me as well! thanks @gohm44

DigitalFeonix commented 10 months ago

I have gotten it working... but, it took more than just removing the old credentials.

I really wish the documentation had a link to the Application Credentials integration page. I didn't know about it until @gohm44 mentioned it.

I first removed the credentials and tried again. I finally got the modal to add the Name, Client ID, and Client Secret. Created a new Secret and used that. Still had the same result with the same "invalid token" in the logs. Tried clearing the app credential and rebooting Home Assistant, and trying again; same result. I downloaded 2023.10.5, cleared the credential, updated the server, and tried again; same result.

It finally took me removing my old Twitch App from the dev console and created a new application for it to be added. After the first load it loaded 176 entities. The list didn't have the streamer I was after, and used the "Reload" option for the integration and after a few minutes my entity count is now 200. I do not know how to verify that this is the correct count of channels I follow, but the streamer I am interested in within the list now.

StellarTransmissions commented 10 months ago

It finally took me removing my old Twitch App from the dev console and created a new application for it to be added. After the first load it loaded 176 entities. The list didn't have the streamer I was after, and used the "Reload" option for the integration and after a few minutes my entity count is now 200. I do not know how to verify that this is the correct count of channels I follow, but the streamer I am interested in within the list now.

twitch limits the api requests to 200 per minute so I have found on mine it doesn't load them all as i follow over 700. going t create a new account with people I want to show up inside home assistant as it doesn't always show the right people online. before you could create a list of the channels you want to follow in the sensors.yaml file but don't think you can do that now. just pulls down every channel you follow

gohm44 commented 10 months ago

You can disable entity which you don't want to monitor but it's not very convenient (I follow ~100). I agree that select specific channel in the integration will be much better, similar to previous yaml way.

zuldero commented 8 months ago

I have gotten it working... but, it took more than just removing the old credentials.

I really wish the documentation had a link to the Application Credentials integration page. I didn't know about it until @gohm44 mentioned it.

I first removed the credentials and tried again. I finally got the modal to add the Name, Client ID, and Client Secret. Created a new Secret and used that. Still had the same result with the same "invalid token" in the logs. Tried clearing the app credential and rebooting Home Assistant, and trying again; same result. I downloaded 2023.10.5, cleared the credential, updated the server, and tried again; same result.

It finally took me removing my old Twitch App from the dev console and created a new application for it to be added. After the first load it loaded 176 entities. The list didn't have the streamer I was after, and used the "Reload" option for the integration and after a few minutes my entity count is now 200. I do not know how to verify that this is the correct count of channels I follow, but the streamer I am interested in within the list now.

What do you mean by 'removing my old Twitch App from the dev console'? I have the same problem; I had old credentials in there. However, after updating them and reinstalling the add-on, it did not resolve the issue. I have all the streamers I follow (a whitelist would be great), but they do not update by themselves. Only when I hit 'reload' do I get the current state (live or not).

issue-triage-workflows[bot] commented 5 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.