home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
70.91k stars 29.56k forks source link

home connect oauth flow is failing #105525

Open kpm4 opened 8 months ago

kpm4 commented 8 months ago

The problem

I just got a bosch induction hob, registered on Home Connect and all is working on the app, so I am trying to integrate with HA, then I created a developer account on HC, created a new application and tried to install the HC integration on HA, but I still get the "error": "unauthorized_client". I tried to logout from developer portal, tried with another browser, disabled default_config, but without any luck, I am using duckdns to access my HA from internet and used my public domain as URI on Home Connect application.

What version of Home Assistant Core has the issue?

core-2023.12.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

home_connect

Link to integration documentation on our website

https://www.home-assistant.io/integrations/home_connect/

Diagnostics information

What I noticed from the error, decoding the jwt token I still see the call to http:/my.home-assistant.io/redirect/oauth instead of https:/MYDOMAIN.duckdns.org:MYPORT/auth/external/callback

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 8 months ago

Hey there @davidmstraub, mind taking a look at this issue as it has been labeled with an integration (home_connect) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `home_connect` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign home_connect` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


home_connect documentation home_connect source (message by IssueLinks)

markkvdb commented 8 months ago

Having the same problem. When I manually change the URL to use my nabu casa external URL I'm asked to fill in my Home Connect credentials. When I click on "Approve", I'm redirected to https://my.ui.nabu.casa/redirect/oauth but I get a 404 error.

unicumnext commented 8 months ago

Same problem here.

CyberLine commented 8 months ago

same problem here. even if i manually change redirect_uri it still fails because in jwt https://my.home-assistant.io/redirect/oauth is hardcoded?

CyberLine commented 8 months ago

Fixed it by changing the URL in https://github.com/home-assistant/core/blob/e83aa864266a08081180edabf24d93c6e8c665d8/homeassistant/helpers/config_entry_oauth2_flow.py#L41 to my instance URL, then restart HA. Afterwards Oauth2 Flow works.

kpm4 commented 8 months ago

where exactly do you change it? under custom_components the home connect integration is not installed yet since the auth flow fails, so where do you change it on HA?

msiegmeth commented 7 months ago

where exactly do you change it? under custom_components the home connect integration is not installed yet since the auth flow fails, so where do you change it on HA?

I had the same issue and noticed that I have never added "default_config:" and "my" to my instance facepalm - after doing so the integration worked. You can check if that may be the issue by adding any integration via the "add integration to MY" button on the integration website - if that fails with an 404 then you may be missing the my integration.

kvor commented 5 months ago

Same problem here. Is there any update?

Zumzod commented 5 months ago

I'm having the same problem. The redirect url points toward https://my.home-assistant.io/redirect/oauth but even setting that up by poiting it towards my http://192.168... won't work. Changing the redirect-url in the URL doesn't work, just end up with a blank page and an error message it failed it HA.

CyberLine commented 5 months ago

I'm having the same problem. The redirect url points toward https://my.home-assistant.io/redirect/oauth but even setting that up by poiting it towards my http://192.168... won't work. Changing the redirect-url in the URL doesn't work, just end up with a blank page and an error message it failed it HA.

You need to set your external domain in the code to get it working.

Zumzod commented 5 months ago

I don't expose my home assistant externally. I got the authentication working some time ago against my internal IP but it stopped working after a while, might have been after the switch to single-key login on their part.

Example from docs with internal ip. image

maciejpolanczyk commented 2 months ago

Hi, I had the same issue.

There are two ways to fix it:

  1. Use My Home integration (which is used by default for Home Connect integration). You just need to go to https://my.home-assistant.io/ and make sure your Home Assistant url is set there, for example: http://homeassistant:8123/ . Next go to https://developer.home-connect.com/ and make sure that Redirect URIs is set to https://my.home-assistant.io/redirect/oauth . Log out from Home Connect for Developers. Wait ~20minutes if you applied any changes there. And now you can start Home Connect Integration. Some people suggest to use private profile in web browser for integration process but in my case it was not needed.

  2. Don't use My Home integration. You need to disable it in default_config in configuraiton.yaml. To achieve this I used https://github.com/tronikos/default_config_disabler . In addition make sure there is no my: in configuration.yaml. Next go to https://developer.home-connect.com/ and make sure that Redirect URIs is set to <your home assistant url>/auth/external/callback, for example: http://homeassistant:8123/auth/external/callback . Log out from Home Connect for Developers. Wait ~20minutes if you applied any changes there. And now you can start Home Connect Integration. Some people suggest to use private profile in web browser for integration process but in my case it was not needed. I noticed that some integrations are not working correctly when default_config_disabler is disabling My Home integration, so after setting up Home Connect integration I enabled My Home integration in default_config_disabler.