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?
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.
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}"