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
71.81k stars 30.06k forks source link

Cannot install homeconnect - Installations shows an error after logging in homeconnect website #81481

Closed FerGitH closed 1 year ago

FerGitH commented 1 year ago

The problem

When I try to install Homeconnect I get an error message after inputting my credentials on the homeconnect site (https://api.home-connect.com/)

I have created a homeconnect account and added the client id and client secret in the configuration yalm

What version of Home Assistant Core has the issue?

2022.10.5

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

Homeconnect

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

This is the error I can see in the log:

2022-11-03 14:55:14.518 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 222, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 82, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 171, in get
    return await super().get(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 96, in get
    result = await self._flow_mgr.async_configure(flow_id)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 280, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 303, in async_step_creation
    token = await self.flow_impl.async_resolve_external_data(self.external_data)
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 169, in async_resolve_external_data
    return await self._token_request(
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 205, in _token_request
    resp.raise_for_status()
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1004, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url=URL('https://api.home-connect.com/security/oauth/token')

Additional information

No response

home-assistant[bot] commented 1 year 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` Change the title of 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.

(message by CodeOwnersMention)


home_connect documentation home_connect source (message by IssueLinks)

jswetzen commented 1 year ago

I'm also unable to authorize. For me I don't get an error log, but after being redirected to the home-connect login page it sends a failed response back to home assistant.

JulianKarhof commented 1 year ago

I also can't get this to work, have tried multiple configurations and redirect urls.

ChristopherNeuwirth commented 1 year ago

+1

AtomToast commented 1 year ago

I have the same issue

danielschmitz87 commented 1 year ago

I also receive the error request rejected by client authorization authority (developer portal)"

sapotero commented 1 year ago

As @AtomToast and @danielschmitz87 i receive all sort of errors from Home Connect API and finaly got this image

Also in the callback url i see the parameter named error_description with value Mandatory+parameter+missing+in+login+request

J0sss commented 1 year ago

I have the same issue as described. It looked like a token expired at first, but after reinstalling the integration I couldn't get it back. Is this perhaps related to the new singlekey authentication for home connect? I set that up using the home connect app and when I now have to login after adding the integration in HA I do get a singlekey login screen in between, but it still results in an error.

jswetzen commented 1 year ago

I installed (Home Connect Alt)[https://github.com/ekutner/home-connect-hass] from HACS now and it just worked. I don't know if this official integration is abandoned or what, but I won't bother with it for now anyway!

xoref commented 1 year ago

I've been pulling my hair for the past few hours - good things I'm bold already πŸ˜† - trying to figure out why OAuth2 is failing. First, I had to find out you can only really use your public address while authenticating (like https://xxx.duckdns.org). After that I got stuck on the OAuth2 callback URL after accepting all @ home-connect with a 500 error: 500 Internal Server Error - Server got itself in trouble ( on http://xxx.duckdns.org/auth/external/callback?code=...&state=...&grant_type=authorization_code )

Trace

2022-11-27 12:26:45.717 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 222, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 82, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 433, in get
    await hass.config_entries.flow.async_configure(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 266, in async_configure
    raise UnknownFlow
homeassistant.data_entry_flow.UnknownFlow

Thanks @jswetzen - I'll try that instead.

sapotero commented 1 year ago

If anyone want to official integration work "properly" - you just need to add hidden input elements to login form:

<input type="hidden" name="response_type" value="code" />
<input type="hidden" name="scope" value="IdentifyAppliance" />
<input type="hidden" name="redirect_uri" value="YourURI" />
<input type="hidden" name="password" value="YourPassword" />

It seem`s to me that the login form is broken somehow With this weird solution i successfully make API works

goranobradovic commented 1 year ago

With this weird solution i successfully make API works

I can confirm this works. In password I put my app's "secret" - not sure if it is actually used. I did it by editing html of add integration dialog in my home assistant, added https://my.home-assistant.io/redirect/oauth as redirect_uri and my app's secret as password, other 2 copied as they are.

J0sss commented 1 year ago

I am trying what you guys suggested, changing the login form. It does seem to change something, I get a page with the old login of home connect. Unfortunately, as I have already enabled singlekey authentication, it redirects me to the singlekey login page as my original home connect login does not work anymore. Adding the suggested elements at the initial login form or at a later stage does not seem to have any effect. Are you not using singlekey yet or am I doing something wrong?

sapotero commented 1 year ago

By my mind it work only you use old login form and you does not enabled singlekey authentication

goranobradovic commented 1 year ago

By my mind it work only you use old login form and you does not enabled singlekey authentication

I have singlekey enabled, and I was redirected there, signed in and then sent back to app... image

Have you signed into singlekey with same account that you used to register as developer? If not then you probably need to set the one you are signing in (on installation of integration) into Home Connect User Account for Testing of your app in developer portal.

J0sss commented 1 year ago

I found the issue now and managed to get it working. My email address for singlekey started with a capital letter, I read somewhere else that that can cause issues. I changed it and after that everything worked like a charm. Thanks for the help!

raregtp commented 1 year ago

If anyone want to official integration work "properly" - you just need to add hidden input elements to login form:

<input type="hidden" name="response_type" value="code" />
<input type="hidden" name="scope" value="IdentifyAppliance" />
<input type="hidden" name="redirect_uri" value="YourURI" />
<input type="hidden" name="password" value="YourPassword" />

It seem`s to me that the login form is broken somehow With this weird solution i successfully make API works

I can confirm this works.....though ended up going with Home Connect Alt from HACS. I didn't even attempt to modify the login form...just adjusted the URL on the tab that the integration opened as was able to get through the settings linking to my SingleKey-ID account. It did not actually complete when I went back to HA, but I'm assuming that's because I had tried multiple times before getting the URL right. Hope this helps someone!

rmjjanssen1 commented 1 year ago

Hi,

Another guy pulling his hair out. Register external URL http://:8123/auth/external/callback in the developer portal but am not able to pass the redirection.

Would somebody be able to provide step by step guide how to get it fixed?

YES! finally got it working. No code/html modification were required, both home connect (alt) integrations work. Key is that the redirect url is specified as it appears the HC cloud service performs AUTHORISATION (check) on this URL if it is allowed and registered under the application you created. Here the solution:

1) at the screen with with "error": "unauthorized_client", examen the URL and look for the &redirect_url= 2) make sure this redirect url is specified in the home connect development portal (under the application you created). It appears the home connect cloud service authorises the redirect URL passed on from Home assistant integration. Give it some time to ripple through after saving. redirect url I used is https://my.home-assistant.io/redirect/oauth (check also if my.home-assistant.io is working for you). For completeness, as I use different e-mail addresses as account ID for developer and app account, I also filled 'Home Connect user account for testing' on the developer application with the account id (e-mail) is used to create app account 3) Go to Home assistant integration page and add either the Home connect or HACS home connect alt custom integration. the latter is far more feature rich than the core integration 4) Click on go the website after you have entered the HC client ID an Auth secret (for HACS HC integration you need to add it to configuration.yaml file) 5) Click on go to website 6) You are redirected to login to home connect, use your App Singlekey ID account to login 7) Allow permissions and link the account to home assistant 8) HC integration should now be added on your integration screen

image

Hope this help others having problems with this.

rmjjanssen1 commented 1 year ago

If anyone want to official integration work "properly" - you just need to add hidden input elements to login form:

<input type="hidden" name="response_type" value="code" />
<input type="hidden" name="scope" value="IdentifyAppliance" />
<input type="hidden" name="redirect_uri" value="YourURI" />
<input type="hidden" name="password" value="YourPassword" />

It seem`s to me that the login form is broken somehow With this weird solution i successfully make API works

Where can I find the source code on Home assisted OS instance (original integration, not HACS)?

sapotero commented 1 year ago

@rmjjanssen1 probably here

DavidMStraub commented 1 year ago

I am not up to date on recent changes to this integration, so I might not be able to help solve these issues, but I am puzzled by some of the posts here - @rmjjanssen1 isn't the procedure you described exactly what is documented here? Including the Redirect URI? So why would anyone need hidden inputs?

B4daa commented 1 year ago

@FerGitH Solution that worked for as described in https://github.com/home-assistant/core/issues/86999

you have to make sure that u dont have any upper case Characters in your single-key e-mail adress. Go to: https://singlekey-id.com/de/home/ and edit your email there, but u have to change it to a second e-mail as you cant just use the same email in lower-case.

Hope this helps :)

nordeep commented 1 year ago

If anyone want to official integration work "properly" - you just need to add hidden input elements to login form:

<input type="hidden" name="response_type" value="code" />
<input type="hidden" name="scope" value="IdentifyAppliance" />
<input type="hidden" name="redirect_uri" value="YourURI" />
<input type="hidden" name="password" value="YourPassword" />

It seem`s to me that the login form is broken somehow With this weird solution i successfully make API works

I can confirm! Successfully added my appliance through Home Connect Alt from HACS. In the Home Connect login form, you need to open Chrome Dev Tools(F12 key). Find <body> - Right Click - Edit as HTML. Find <input type="hidden" and add code below. Click on anywere in Dev tools to close HTML edit form. After that, type your email in Login form.

issue-triage-workflows[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment πŸ‘ This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.