Access through Companion app denied but okay through browser

I’m having an odd issue where I can’t connect to my Home Assistant instance externally from the Home Assistant Companion app, but I can access the cloud instance (nabu casa url) through my browser on the same device.

I can access Home Assistant fine through the app on my home network as well, just not externally.
Screenshots attached and logs below:

Login attempt or request with invalid authentication from localhost (127.0.0.1). Requested URL: '/auth/token'. (Home Assistant/2023.8.2-10992 (Android 13; M2102J20SG))
Login attempt or request with invalid authentication from localhost (127.0.0.1). Requested URL: '/api/websocket'. (Mozilla/5.0 (Linux; Android 13; M2102J20SG Build/TQ3A.230705.001.B4; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/116.0.0.0 Mobile Safari/537.36 Home Assistant/2023.8.2-10992 (Android 13; M2102J20SG))


Any idea why this might be the case?
It was fine previously, not sure anything has changed…

I have ‘Use Home Assistant Cloud’ enabled in the settings and have added my Home WiFi SSID and url for internal connection.

In the unable to connect pop-up click on settings then go to troubleshooting> show and share logs and pull the logs to see why it failed

First guess: have you enabled the “Can only log in from the local network” setting for this user? :slight_smile:

Find or check here: Settings > People > Users and click that user. In the popup directly under the name you can switch that setting.

Ah, my bad. I thought the logs were just what I pasted above.

That log is >300 lines, so I’ve pasted it here.

I don’t know what I’m looking at unfortunately.

Could it be something to do with Refresh tokens? I have a heap there and the last one related to 127.0.0.1 is:

Refresh token for https://[myurl].ui.nabu.casa/
Created last month
Last used 20 hours ago from 127.0.0.1 

Nope. Unchecked in settings. And using the same user I can log in to my cloud url from a browser fine. just not from the app.

Ya try to log out in the app and log back in should solve that issue.

Hmm… I had tried that and still had the same issue before posting. But maybe because I logged back in while on the home network?

Logged out and then logged in while on mobile data this time and was initially told unable to login due to untrusted network (as you’d expect), but used home assistant local login with user credentials and got in fine, and seems to be working okay when off home wifi.

Strange… Thanks for your help.

I don’t think you can login and get the proper token if using trusted network when logging into the mobile app. The token is probably only valid in the given circumstance.

I just upgraded to 12.1 and have the same issue.

What was the solution?

Same here after upgrading to 12.2. Even rolled back the Core and still persists. So appears to be the OS.

Any ideas?

I am also dealing with these symptoms. In my setup, I have a local DNS server for requests from within my network pointing to a local IP (192.168.1.9), and a cloudflare tunnel for requests from outside the network. It seems that the app somehow remembers the IP from the local DNS, even when connecting remotely, which will obviously fail. The relevant line in my logs is:

01-24 18:47:19.520 25202 31987 E SensorReceiver: Error while getting core config to sync sensor status
01-24 18:47:19.520 25202 31987 E SensorReceiver: io.homeassistant.companion.android.common.data.integration.IntegrationException: java.net.SocketTimeoutException: failed to connect to homeassistant.ssenhorst.nl/192.168.1.9 (port 443) from /10.66.42.219 (port 38480) after 10000ms

Does the android app keep some local DNS cache somewhere?

Given the logs provided by @jonaseymour, I think we are likely dealing with a different issue which does share the same symptoms.

PS: @jonaseymour, be aware that there is personally identifiable location information in the logs you shared. It might be worth redacting some sensitive info…