Andre0512 / hon

Home Assistant integration for Haier hOn: support for Haier/Candy/Hoover home appliances like washing machines and air conditioners in 28 languages.
MIT License
1.22k stars 2.5k forks source link

Authentication Error When Adding hOn Integration using a Google account that has 2FA turned on #159

Open swampylee opened 3 months ago

swampylee commented 3 months ago

I've previously been using the integration with a non-google account but needed to switch to using a google account. So I re-setup the hOn ios application and added the appliance without an issue - logging in using my google account. This all works fine.

Then I removed the hOn integration from HA, restarted it and then added the integration again. Entering google account and password - it adds the integration but then fails to login (logs below).

If I go to account2.hon-smarthome.com and login, it works ok but the initial login did require me to confirm a login on my phone (2FA).

If I use pyhOn to try and login from my HA host I get the same unable to login error.

Is there a way to get around this or do I have to revert back to a login without 2FA active on the google account?

Thanks, Lee

Logs:

2024-01-24 12:11:50.085 ERROR (MainThread) [pyhon.connection.auth] hOn Authentication Error
  1     401 - https://account2.hon-smarthome.com/setup/secur/RemoteAccessAuthorizationPage.apexp?source={redacted}&display=touch
  2     302 - https://account2.hon-smarthome.com/s/login?display=touch&ec=302&inst=R2&startURL=/setup/secur/RemoteAccessAuthorizationPage.apexp?source%{redacted}3Dtouch
  3     301 - https://account2.hon-smarthome.com/s/login/?display=touch&ec=302&inst=R2&startURL=/setup/secur/RemoteAccessAuthorizationPage.apexp?sourceRedacted3Dtouch
  4     200 - https://account2.hon-smarthome.com/s/login/?language=en_US&display=touch&ec=302&inst=R2&startURL=%2Fsetup%2Fsecur%2FRemoteAccessAuthorizationPage.apexp%3Fsource{redacted}26display%3Dtouch&System=IoT_Mobile_App&RegistrationSubChannel=hOn
  5     200 - https://account2.hon-smarthome.com/s/sfsites/aura?r=3&other.LightningLoginCustom.login=1
ERROR - 200 - https://account2.hon-smarthome.com/s/sfsites/aura?r=3&other.LightningLoginCustom.login=1
=============== Response ===============
{"actions":[{"id":"79;a","state":"SUCCESS","returnValue":"Your login attempt has failed. Make sure the username and password are correct.","error":[]}],"context":{"mode":"PROD","app":"siteforce:loginApp2","contextPath":"/s/sfsites","pathPrefix":"","fwuid":"{redacted}","mlr":1,"loaded":{"APPLICATION@markup://siteforce:loginApp2":"{redacted}"},"globalValueProviders":[{"type":"$Global","values":{"eswConfigDeveloperName":{"writable":true,"defaultValue":""},"isVoiceOver":{"writable":true,"defaultValue":false},"setupAppContextId":{"writable":true,"defaultValue":""},"density":{"writable":true,"defaultValue":""},"srcdoc":{"writable":false,"defaultValue":false},"appContextId":{"writable":true,"defaultValue":""},"dynamicTypeSize":{"writable":true,"defaultValue":""}}}],"enableAccessChecks":true,"apce":1,"dns":"c","lairn":[],"laerc":[],"lav":"59","mna":{"lightning":"interop"},"lff":{"ENABLE_MIXED_SHADOW_MODE":false,"ENABLE_LEGACY_SCOPE_TOKENS":false,"DISABLE_LIGHT_DOM_UNSCOPED_CSS":false},"arse":1,"acaf":1,"services":["markup://lightning:configProvider","markup://force:salesforceScopedModuleResolver","markup://force:ldsEngineCreator","markup://instrumentation:locatorService"]},"perfSummary":{"version":"core","request":5,"actions":{"79;a":{"total":3,"db":1}},"actionsTotal":3,"overhead":0}}
========================================
2024-01-24 12:11:50.085 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry {redacted}@gmail.com for hon
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 406, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/hon/__init__.py", line 32, in async_setup_entry
    hon = await Hon(
          ^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyhon/hon.py", line 66, in create
    await self.setup()
  File "/usr/local/lib/python3.11/site-packages/pyhon/hon.py", line 97, in setup
    appliances = await self.api.load_appliances()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyhon/connection/api.py", line 77, in load_appliances
    async with self._hon.get(f"{const.API_URL}/commands/v1/appliance") as resp:
  File "/usr/local/lib/python3.11/contextlib.py", line 204, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyhon/connection/handler/base.py", line 64, in get
    async with self._intercept(*args, **kwargs) as response:
  File "/usr/local/lib/python3.11/contextlib.py", line 204, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyhon/connection/handler/hon.py", line 61, in _intercept
    kwargs["headers"] = await self._check_headers(kwargs.get("headers", {}))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyhon/connection/handler/hon.py", line 51, in _check_headers
    await self.auth.authenticate()
  File "/usr/local/lib/python3.11/site-packages/pyhon/connection/auth.py", line 258, in authenticate
    if not (url := await self._login()):
                   ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyhon/connection/auth.py", line 195, in _login
    await self._error_logger(response)
  File "/usr/local/lib/python3.11/site-packages/pyhon/connection/auth.py", line 96, in _error_logger
    raise exceptions.HonAuthenticationError("Can't login")
pyhon.exceptions.HonAuthenticationError: Can't login
swampylee commented 3 months ago

I setup a new Google account without 2FA and I still can't get the integration to work. Have they already stopped people accessing it? It's also interesting that the Google Home / Assistant Integration seems not to work either.........

The hOn app however is working fine using the same new Google account.

axel2906 commented 2 months ago

I've the same issue. I updated HA to 2024.2.1 and now impossible to get the integration to work (i don't have the 2FA for hOn)

i tried to change the password but it didn't help (app works on my phone)

I removed and re-added integration but still have same issue

Logs:

2024-02-13 19:16:27.414 ERROR (MainThread) [pyhon.connection.auth] hOn Authentication Error
  1     200 - https://account2.hon-smarthome.com/setup/secur/RemoteAccessAuthorizationPage.apexp?source=XXXX
  =============== Response ===============

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

<script>
function redirectOnLoad() {
if (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('/_ui/system/security/ChangePassword?retURL=%2F_ui%2Fidentity%2Foauth%2Fui%2FAuthorizationPage%3Fsource%XXXXX
; }  else 
if (window.location.replace){ 
window.location.replace('/_ui/system/security/ChangePassword?retURL=%2F_ui%2Fidentity%2Foauth%2Fui%2FAuthorizationPage%3Fsource%XXXX
} else {
window.location.href ='/_ui/system/security/ChangePassword?retURL=%2F_ui%2Fidentity%2Foauth%2Fui%2FAuthorizationPage%3Fsource%XXXX%26display%3Dtouch&setupid=ChangePassword';
} 
} 
redirectOnLoad();
</script>

</head>

</html>

========================================

2024-02-13 19:16:27.414 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry abc@gmail.com for hon
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 444, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/hon/__init__.py", line 32, in async_setup_entry
    hon = await Hon(
          ^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyhon/hon.py", line 66, in create
    await self.setup()
  File "/usr/local/lib/python3.12/site-packages/pyhon/hon.py", line 97, in setup
    appliances = await self.api.load_appliances()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/api.py", line 77, in load_appliances
    async with self._hon.get(f"{const.API_URL}/commands/v1/appliance") as resp:
  File "/usr/local/lib/python3.12/contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/handler/base.py", line 64, in get
    async with self._intercept(*args, **kwargs) as response:
  File "/usr/local/lib/python3.12/contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/handler/hon.py", line 61, in _intercept
    kwargs["headers"] = await self._check_headers(kwargs.get("headers", {}))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/handler/hon.py", line 51, in _check_headers
    await self.auth.authenticate()
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/auth.py", line 256, in authenticate
    if not await self._load_login():
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/auth.py", line 104, in _load_login
    login_url = await self._introduce()
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/auth.py", line 128, in _introduce
    await self._error_logger(response)
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/auth.py", line 96, in _error_logger
    raise exceptions.HonAuthenticationError("Can't login")
pyhon.exceptions.HonAuthenticationError: Can't login
swampylee commented 2 months ago

I've the same issue. I updated HA to 2024.2.1 and now impossible to get the integration to work (i don't have the 2FA for hOn)

i tried to change the password but it didn't help (app works on my phone)

I removed and re-added integration but still have same issue

Logs:

2024-02-13 19:16:27.414 ERROR (MainThread) [pyhon.connection.auth] hOn Authentication Error
  1     200 - https://account2.hon-smarthome.com/setup/secur/RemoteAccessAuthorizationPage.apexp?source=XXXX
  =============== Response ===============

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

<script>
function redirectOnLoad() {
if (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('/_ui/system/security/ChangePassword?retURL=%2F_ui%2Fidentity%2Foauth%2Fui%2FAuthorizationPage%3Fsource%XXXXX
; }  else 
if (window.location.replace){ 
window.location.replace('/_ui/system/security/ChangePassword?retURL=%2F_ui%2Fidentity%2Foauth%2Fui%2FAuthorizationPage%3Fsource%XXXX
} else {
window.location.href ='/_ui/system/security/ChangePassword?retURL=%2F_ui%2Fidentity%2Foauth%2Fui%2FAuthorizationPage%3Fsource%XXXX%26display%3Dtouch&setupid=ChangePassword';
} 
} 
redirectOnLoad();
</script>

</head>

</html>

========================================

2024-02-13 19:16:27.414 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry abc@gmail.com for hon
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 444, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/hon/__init__.py", line 32, in async_setup_entry
    hon = await Hon(
          ^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyhon/hon.py", line 66, in create
    await self.setup()
  File "/usr/local/lib/python3.12/site-packages/pyhon/hon.py", line 97, in setup
    appliances = await self.api.load_appliances()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/api.py", line 77, in load_appliances
    async with self._hon.get(f"{const.API_URL}/commands/v1/appliance") as resp:
  File "/usr/local/lib/python3.12/contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/handler/base.py", line 64, in get
    async with self._intercept(*args, **kwargs) as response:
  File "/usr/local/lib/python3.12/contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/handler/hon.py", line 61, in _intercept
    kwargs["headers"] = await self._check_headers(kwargs.get("headers", {}))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/handler/hon.py", line 51, in _check_headers
    await self.auth.authenticate()
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/auth.py", line 256, in authenticate
    if not await self._load_login():
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/auth.py", line 104, in _load_login
    login_url = await self._introduce()
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/auth.py", line 128, in _introduce
    await self._error_logger(response)
  File "/usr/local/lib/python3.12/site-packages/pyhon/connection/auth.py", line 96, in _error_logger
    raise exceptions.HonAuthenticationError("Can't login")
pyhon.exceptions.HonAuthenticationError: Can't login

The only way I could get things to work in the end was to avoid using a Google account. I setup a new outlook.com account, used that to sign into hOn, add the washing washing / dryer etc and then once they are added to the app and working setup the HA integration using the non-google account and everything worked fine. So I would recommend avoiding using 2FA and also avoid google accounts. Hope this helps.

axel2906 commented 2 months ago

without doing anything it is now working again... sometimes you must wait to bring everything ok...