Invalid client id or redirect uri

Fresh install Home Assistant v0.101.3, on a Raspberry Pi Zero W with Python3.7 virtual environment, configuration.yaml as out of the box.

On the Home Assistant iOS app v1.5.1 I get the “Invalid client id or redirect uri” error.
Tried both the local address of Raspberry Pi, and the DDNS address and didn’t work.
Both of them work if I open them from the browser instead of the app.

Someone has an idea of what should I check?

If you have ddns setup, that’s what you have to use for the url with the following format https://xxx.duckdns.org

You have to verify that the ddns url works OUTSIDE your home network. I.E. Disconnect from wifi and check using LTE or equivalent in a browser on your phone.

1 Like

I verified that DDNS address works from outside my network. Also, I don’t use SSL so the protocol should be “http” instead of “https”.

But let’s put the DDNS address apart for now. I would like to focus on the reason why I can’t access from my local IP.

I put “http://RASPBERRYPI_IP:8123” in Home Assistant iOS app, and I get that error.
If I type it in the browser, I can access.

From the iOS app, the redirected URL is the following (not working):
RASPBERRYPI_IP:8123/auth/authorize?response_type=code&client_id=https://home-assistant.io/iOS&redirect_uri=homeassistant://auth-callback

From the browser, the redirected URL is the following (working):
RASPBERRYPI_IP:8123/auth/authorize?response_type=code&redirect_uri=http%3A%2F%2FRASPBERRYPI_IP%3A8123%2F%3Fauth_callback%3D1&client_id=http%3A%2F%2FRASPBERRYPI_IP%3A8123%2F&state=eyJoYXNzVXJsIjoiaHR0cDovLzE5Mi4xNjguMTc4LjI2OjgxMjMiLCJjbGllbnRJZCI6Imh0dHA6Ly8xOTIuMTY4LjE3OC4yNjo4MTIzLyJ9

Does it connect when you turn on advanced and use internal URL? You’ll need to add your network name and just use the same http://ip:8123 as the internal url.

No success, settings as the image below

what happens when you try to save? Does an error appear or do you get a log in?

It loads the login page, but instead of the login form it appears the red error “invalid client id or redirect uri”.

I’ve just tried with an iPad and I obtain the same result.

This is the relevant part of the logs:

Nov 18 21:32:57 raspberrypi hass[1711]: 2019-11-18 21:32:57 ERROR (MainThread) [homeassistant.components.auth.indieauth] Timeout while looking up redirect_uri https://home-assistant.io/iOS
Nov 18 21:32:57 raspberrypi hass[1711]: 2019-11-18 21:32:57 WARNING (MainThread) [homeassistant.components.http.ban] Login attempt or request with invalid authentication from IPHONE_IP

I’m guessing it has to do with your base url then inside the http: section of HA. Set that to your IP… or ddns if you’re going to use that.

Tried that too, no success. I’ve tried both

http:
  base_url: http://RASPBERRYPI_IP:8123

and

http:
  base_url: RASPBERRYPI_IP:8123

same result.

I observe that the problem relies on the fact the iOS app puts the string “redirect_uri:homeassistant” in the redirected URL, while when accessing from browser that string is "redirect_uri:http://RASPBERRYPI_IP:8123"
Someone knows why?

1 Like

are you restarting between changing the base_url? IIRC the top one you posted is correct.

but that is the one which gives me the invalid client id error

Yes I restart after changing base_url through the command

sudo systemctl restart home-assistant@homeassistant && sudo journalctl -f -u home-assistant@homeassistant

Regardless of the base_url I set, that redirected URL remains the same: is this expected?

Not sure as I’ve never had to dig this deep.

Have you tried setting up lets encrypt w/ ddns. It’s possible that the app requires SSL. I’ve never used it without SSL to be honest.

It did work in the past, without SSL, with previous versions of HA. If I remember well also with this 0.101.3, but something’s clearly changed, maybe after a reinstall.
Since I’m on a fresh install of HA it is clearly something related to my environment but I don’t know where to look…

I could for example set the logger to DEBUG level for the http component… which would be the syntax in configuration.yaml?

Hi, I have got the same error “Invalid client id or redirect uri”
Everything was OK, but from version 0.100 I can’t login using app. No problem with browser.

Unfortunately I still have to find a solution to this problem, which I don’t know if it’s a bug or not.
I tried reinstalling Home Assistant & iOS app several times; I reset all the python3.7 virtual environment; I tried installing different HA versions.
I got a couple of answers on Discord channel but found it not very responsive to questions outside the topic that is going on in the chat.

The only thing that worked was to downgrade iOS app to v1.1.1, which I guess has a different type of authentication method.
Current v1.5.1 and beta v2.0 give this problem to me, on different devices.

I also have this issue. Can you reach your HA-installation via browser from outside your network? This also doesn’t work for me: “Unable to connect to Home Assistant”.

Update: My last statement was wrong: I actually can reach my home assistant from outside my network.

yes I can. both local and external DDNS IP work correctly if accessed from browser. the problem is only in the iOS app.

After trying to completely disable IPv6 from my network as suggested by the app developer on the Discord channel, without solving the issue, I finally flashed the last version of Raspbian Buster on the Raspberry Pi.
On top of that brand new OS I followed the manual installation instructions (which means I also upgraded to HA v0.102.0), and I can report the issue disappeared on the v2.0beta and v1.5.1 iOS app.

I still don’t know the reason of the problem but I consider the issue closed.

Ran into this problem when upgrading to new iOS 2.0.0 Companion.
Finally got it working after changing server DNS resolver to 8.8.8.8 instead of my internal pihole DNS.