cnorick/ha-auto-guest-login

redirect not working

Closed this issue · 9 comments

Chrome console:
GET http://ha.1156rbr.ca:8675/api/getRedirectUri net::ERR_CONNECTION_REFUSED
(anonymous) @ (index):50
Uncaught (in promise) TypeError: Failed to fetch
(anonymous) @ (index):50
Promise.then (async)
(anonymous) @ (index):52
GET http://ha.1156rbr.ca:8675/favicon.ico net::ERR_CONNECTION_REFUSED
:8675/favicon.ico:1

Safari:
[Error] Unhandled Promise Rejection: Not implemented on this platform
[Error] Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'i.generateKey')
promiseEmptyOnRejected (content-script.js:75:780)
promiseReactionJob
[Error] Failed to load resource: Could not connect to the server. (getRedirectUri, line 0)
[Error] Unhandled Promise Rejection: TypeError: Load failed
promiseEmptyOnRejected
promiseReactionJob

let me know if you need any other information

Is http://ha.1156rbr.ca the url you use to access Home Assistant from you local network?

Hi @cnorick - is there anything that I can do to get this going ?
would be a very useful feature for our guests (and get them off my back ;)
this is the errors that I get in the browser:

Screen Shot 2023-04-19 at 15 53 15

Pls note that the internal URL has changed to 1156rbr.ca. (http://1156rbr.ca to be precise, I use Nginx Proxy Manager to redirect port 80 to 8123).

Unfortunately I do not see anything in the logs that would help (me) - here they are anyway:

s6-rc: info: service s6rc-oneshot-runner: starting s6-rc: info: service s6rc-oneshot-runner successfully started s6-rc: info: service fix-attrs: starting s6-rc: info: service fix-attrs successfully started s6-rc: info: service legacy-cont-init: starting s6-rc: info: service legacy-cont-init successfully started s6-rc: info: service legacy-services: starting s6-rc: info: service legacy-services successfully started (node:79) ExperimentalWarning: Importing JSON modules is an experimental feature. This feature could change at any time (Use node --trace-warnings ... to show where the warning was created) HomeAssistant found on port 8123 Auto Guest Login at port 8675

A few more questions:

  1. Are you using the addon to run the server? Or self hosting, or using the separate docker container?
  2. You're able to see the welcome page when you visit the guest url? But it still fails to retrieve the redirect url?
  3. Is it possible your reverse proxy has a rule blocking the /api route?

Oh! Actually, there definitely seems to be something blocking the addon server from receiving the getRedirectUrl request. If that request hit the server, it would log something like this:

posted ha_auto_login_guest_logged_in event
recieved request from http://homeassistant.local
redirecting to http://homeassistant.local:80/lovelace-guest/guest

Q1: I'm using add-on (straight out of the box)
Q2: I do get the welcome page but it fails to the redirect url (and also the faviocn btw)
Q3: it shouldn't (but apparently does something) - am not terribly familiar with nginx - that's why I'm running the add-on (straight out of the box as well).

Did the following
#1 disable the Nginx proxy manager
#2 re-login to HA as the URL has now changed (in my case it's now http://1156rbr.ca:8123)
#3 start guest access add-on
#4 load the 'OPEN WEB UI' >> works as before
#5 access the guest page (http://1156rbr.ca:8675) >> works as before
the error messages on the client side are the same as before
#6 looking at the logs in HA this looks now different (see below)

the add-on now crashes after the first load to the guest page
this might have happened before but I had the HA watchdog on so i might no have seen this

Logs:

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
(node:79) ExperimentalWarning: Importing JSON modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
HomeAssistant found on port 8123
Auto Guest Login at port 8675
posted ha_auto_login_guest_logged_in event
recieved request from http://1156rbr.ca
redirecting to http://1156rbr.ca:8123//dashboard-guest
file:///app/node_modules/node-fetch/src/index.js:95
			reject(new FetchError(`request to ${request.url} failed, reason: ${error.message}`, 'system', error));
			       ^
FetchError: request to http://1156rbr.ca:8123/auth/login_flow failed, reason: getaddrinfo ENOTFOUND 1156rbr.ca
    at ClientRequest.<anonymous> (file:///app/node_modules/node-fetch/src/index.js:95:11)
    at ClientRequest.emit (node:events:525:35)
    at Socket.socketErrorListener (node:_http_client:481:9)
    at Socket.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  type: 'system',
  errno: 'ENOTFOUND',
  code: 'ENOTFOUND',
  erroredSysCall: 'getaddrinfo'
}
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

Just to be sure: did the same again but with Nginx running - result is the same (i.e add-on crashes log is the same as above). So it's not Nginx but something with add-on... but at least we have a log now ;) - hope this helps, thanks for looking into this and let me know if you need any further info

Thanks for detailed info!

That's really interesting. It looks like its a DNS problem. The addon is unable to find the domain name 1156rbr.ca. When you land on the welcome page, the addon starts the login process by sending the provided username/password to the home assistant instance that it assumes is at the same domain (1156rbr.ca in your case).

What seems to be happening is that when the addon tries to make a request to that address, it can't find the domain name and crashes. I'm not sure exactly how to fix this; you somehow need to get the addon to see that 1156rbr.ca is a valid domain name on your network (I think there may be multiple approaches for this).

Alternatively, you can see if it works by accessing home assistant directly using its ip address. (you can probably quickly find it with dig 1156rbr.ca on the command line). If everything works right when you do that, I'd feel confident saying that the above is correct about your problem.

That did the trick - my HA instance sits in a separate network and does not use the same DNS as the admin workstation i'm using. Logging in to HA via the IP address and loading the guest access then works. Thanks for your advice !!

Request #1: An optional configuration entry that would allow me to set the URL instead of extracting it from the admin request.

Request #2: Try to not just crash if the DNS can't be resolved - am not familiar with JS but am sure there is some exception handling available.

Both of these are not urgent but nice to have. Feel free to close this issue or keep it to track the requests - either is fine with me.

Thanks again for your help !!

Glad you got it worked out! Feel free to open other issues for those two things if you have the time. Next time I work this project, or if someone else wants to make PRs, they'll have some work ready to do.