Core: Spotify component will not load new client id and secret

Created on 25 May 2020  路  16Comments  路  Source: home-assistant/core

The problem


When loading the integration via the UI (after filling in the credentials in configuration.yaml) it will open the callback to my previously defined local ip. This results in INVALID_CLIENT: Invalid redirect URI and in the URL my local ip is listed, which I believe is to be expected. After creating a new application in the spotify dashboard (with my external accessible URL, proxied by traefik) and updating the credentials in the configuration.yaml, the same error will be given. However, in the URL of the browser, still the previously configured local ip is listed instead of the newly defined external ip.

This leads me to believe that Home Assistant reuses my old Spotify id and secret.

Environment

  • Home Assistant Core release with the issue: 0.110.1, 0.108.9 (updated from 0.97.2)
  • Last working Home Assistant Core release (if known): 0.97.2
  • Operating environment (Home Assistant/Supervised/Docker/venv): Home Assistant
  • Integration causing this issue: Spotify
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/spotify/

Problem-relevant configuration.yaml

homeassistant:
  external_url: !secret external_url
  internal_url: !secret internal_url

[...]

spotify:
  client_id: !secret spotify_clientid
  client_secret: !secret spotify_clientsecret

Traceback/Error logs

Could not find any relevant logs.

Additional information

spotify

Most helpful comment

I had a look at the get_url() method of home assistant and noticed that the internal_url always prevails the external_url unless specified as can be seen in PR #35224 . As I didn't configure the internal URL I would have expected it would go straight for the external URL.

I currently solved it like this:

homeassistant:
  external_url: !secret external_url
  internal_url: !secret external_url

Perhaps my problem was that I had filled in an internal_url before but removed it earlier today?

All 16 comments

I got a similar problem. I just configured Spotify for the first time within HA (0.110). Within Spotify I configured the external URL like I did with the external URL in HA. I left out the internal URL in HA as I don't have any.

After setting up Spotify in YAML and then configuring through the GUI, I noticed that HA uses the redirect-uri for my internal IP rather then my external URL.

I had a look at the get_url() method of home assistant and noticed that the internal_url always prevails the external_url unless specified as can be seen in PR #35224 . As I didn't configure the internal URL I would have expected it would go straight for the external URL.

I currently solved it like this:

homeassistant:
  external_url: !secret external_url
  internal_url: !secret external_url

Perhaps my problem was that I had filled in an internal_url before but removed it earlier today?

spotify documentation
spotify source
(message by IssueLinks)

Thanks for the research Peter! When using

homeassistant:
  external_url: !secret external_url
  internal_url: !secret external_url

the spotify link now shows my external_url in the address bar. However, the same error is given: INVALID_CLIENT: Invalid redirect URI, thus for me the problem has not been solved yet.

Just to make sure, did you validate you filled in the correct redirect URI within the Spotify settings of your new set up?

I believe so. When opening the redirect URI ([external_url]:443/auth/external/callback) from the Spotify settings, the link proves to be correct by the following error HomeAssistant gives:
Missing code or state parameter in [external_url]/auth/external/callback.
However, when I look at this error, it shows http:// instead of the https:// defined in external_url. Can that be causing some troubles?

The Spotify dashboard shows 0 active users by the way. Previously (0.97.2) it was bigger than 0, but I deleted my old config to be sure it could not be using that config anymore.

Hello good afternoon.
I have into the same problem in HA version 0.110.1, after investigating and examining logs and etc, I have noticed in the Spotify Developer dashboard, if you access the application you have a field where you have to add the URIs to perform the process satisfactorily, it has been solved for me and I already have it working I attach a screenshot of where to enter the URIs.

URIs

I hope it helps you!

Cheers

Thanks for the suggestion, @kronostimes. I have used that place as well to put in my externally accessible address (domainXXX.com:443/auth/external/callback). Why did you include some links without /auth/external? And which addresses did you use? Your own domain name, your public and local IP? Are they all necessary for you to function?

Hi ! i've got similar problem on fresh install of spotify integration.

I configured external url xxx.duckdns.org and internal url with local ip address 192.xxxx.
Spotify dev account callback url have xxx.duckdns.org

Problem appear when you try to integrate spotify : the popup login to your spotify account return the error "INVALID_CLIENT: Invalid redirect URI" .
After investigate, it's the internal URL wrote instead of external in this URL call

Replacing internal url by external url in hass config works fine, but not expected working

I am experiencing the same Spotify component issue setting up a new install of HA. I have set up Spotify several times in the past successfully and I know to edit the white list. But now the redirect URL always shows my internal ip not my Nabu Casa external address that I put in the white list. When I manually edited the redirect URL in the browser, I got the authorization screen but then the "setting up integration" hangs and doesn't finish. Manually editing the redirect URL with my Nabu Casa address after that 1 authorization fails now and web page indicates:
500 Internal Server Error Server got itself in trouble

Log file:

`Log Details (ERROR)
Logger: aiohttp.server
Source: helpers/config_entry_oauth2_flow.py:167
First occurred: 4:03:37 PM (5 occurrences)
Last logged: 4:12:29 PM

Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/aiohttp/web_protocol.py", line 418, in start
resp = await task
File "/usr/local/lib/python3.7/site-packages/aiohttp/web_app.py", line 458, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.7/site-packages/aiohttp/web_middlewares.py", line 119, in impl
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/real_ip.py", line 39, in real_ip_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 73, in ban_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 125, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 136, in get
return await super().get(request, flow_id)
File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 91, in get
result = await self._flow_mgr.async_configure(flow_id)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 153, in async_configure
result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 201, in _async_handle_step
result: Dict = await getattr(flow, method)(user_input)
File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 248, in async_step_creation
token = await self.flow_impl.async_resolve_external_data(self.external_data)
File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 142, in async_resolve_external_data
"redirect_uri": self.redirect_uri,
File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 167, in _token_request
resp.raise_for_status()
File "/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 946, in raise_for_status
headers=self.headers)
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url='https://accounts.spotify.com/api/token'`

I have redone the process several times deleting the configuration entry, the app from the Spotify dashboard and re-adding it all back. But no luck.

I think and as I remember what is really important is to add the URLs to the Spotify site in your application when you create it in Spotify when you create the API

Thanks for the suggestion, @kronostimes. I have used that place as well to put in my externally accessible address (domainXXX.com:443/auth/external/callback). Why did you include some links without /auth/external? And which addresses did you use? Your own domain name, your public and local IP? Are they all necessary for you to function?

No, they are not all necessary, but I think I remember that I added them in case I made any exceptions as they are a link

I am running Homeassistant Core 0.110.4 and I did put the external and internal URLs in the General Configuration section that was implemented in this release of Core. But, the Spotify integration still tries to open the Spotify web page using the internal ip. Perhaps the change from the base_url method to this new method broke the Spotify authorization part of the integration.

Could it have anything to do with my reverse proxy setup? I am currently running Traefik V2 on a separate box, which proxies to the RPi I'm using for Home Assistant. Not sure if I should maybe include more headers or something else.

http:
  routers:
    raspberry_pi:
      service: homeassistant
      rule: "Host(`EXTERNAL_ADRESS`)"
      entryPoints:
        - websecure
      tls:
        certResolver: lets-encr

  services:
    homeassistant:
      loadBalancer:
        servers:
          - url: "LOCAL_IP:8123"

Hello good afternoon.
I have into the same problem in HA version 0.110.1, after investigating and examining logs and etc, I have noticed in the Spotify Developer dashboard, if you access the application you have a field where you have to add the URIs to perform the process satisfactorily, it has been solved for me and I already have it working I attach a screenshot of where to enter the URIs.

URIs

I hope it helps you!

Cheers

THIS is the solution. If you start the request and it says "INVALID_CLIENT: Invalid redirect URI", look at the URL. This URL which is called an denied has to be added at the Spotify-Developer App.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

balloob picture balloob  路  371Comments

raccettura picture raccettura  路  142Comments

neotrunks picture neotrunks  路  169Comments

Gio76 picture Gio76  路  223Comments

winterscar picture winterscar  路  251Comments