Spotify wont configure :: Invaid redirect URI

Hey Guys,

since a few day ive got the error “INVALID_CLIENT: Invalid redirect URI” while trying to setup the Spotify Intergration. I have stored the IP address including port and co as the redirect URI.

But in the practice what the spotify intergration is: “…redirect_uri=https://my.home-assistant.io/redirect/oauth&state=…”

WTF? I have settet the IP Adress and not the Cloud Domain?
What can i do to fix this?

Cheers,
Basti

I’m also the same

Same here…

Anyone who solved this issue

I got exactly the same redirect uri: Link to OAuth2 Authorize Callback – My Home Assistant

Same, I’ve opened an issue on Github: Spotify integation wrong redirect when importing from yaml · Issue #73113 · home-assistant/core · GitHub

You have to add ‘Link to OAuth2 Authorize Callback – My Home Assistant’ to the redirect URI’s on the application settings page for it to work. Just the http://homeassistant.local:8123/auth/external/callback isn’t sufficient.

1 Like

More specifically, from the Github thread, adding both urls just like this worked for me:

https://my.home-assistant.io/redirect/oauth
http://homeassistant.local:8123/auth/external/callback

Thanks, WaxBear

1 Like

Where is this located? Certainly not at the link you posted. Or are you saying you need to put that link in the Spotify Developer’s App or? Please speak as if people do not understand …

Link to OAuth2 Authorize Callback – My Home Assistant seems to be kind of hardcoded.
I somehow hacked
/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py
to always return f"{ha_host}{AUTH_CALLBACK_PATH}" instead of MY_AUTH_CALLBACK_PATH
The proper way would have been to remove “my” from self.hass.config.components but I was not able to find this entry in my docker based 2022.11 config.
Using this hack I was able to authenticate with Home Connect and Neato Oauth2 Providers.

    @property       
    def redirect_uri(self) -> str:
        """Return the redirect uri."""
        # if "my" in self.hass.config.components:
        #     return MY_AUTH_CALLBACK_PATH
                                        
        if (req := http.current_request.get()) is None:
            raise RuntimeError("No current request in context")
                                                    
        if (ha_host := req.headers.get(HEADER_FRONTEND_BASE)) is None:
            raise RuntimeError("No header in request")
                                                      
        return f"{ha_host}{AUTH_CALLBACK_PATH}"
1 Like

Brilliant, that made the trick

nice! Thanks a lot! These are the steps I took (for later reference):

  1. Disable protection mode of the Advanced SSH Haddon
  2. Dive into the HA docker: docker exec -it $(docker ps -f name=homeassistant -q) bash
  3. edit the file: vi /usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py
  4. Go to that line, Press i edit and press escape
  5. `:wq’ to save and quit.
  6. Run integratie Setup
  7. Undo edit
  8. Enable protection mode