rospogrigio / daikin_residential

Cloud control of Daikin devices that are supported by Daikin Residential Controller app.
GNU General Public License v3.0
284 stars 37 forks source link

Captcha required in login? #49

Closed ricardojdsilva87 closed 2 years ago

ricardojdsilva87 commented 2 years ago

Hello, First of all thanks for your work! I've tried adding the residential controller to home assistant adding it trought the UI. Inserted my email address and also password. On the Daikin Residential Controller app, I've created the account using google login connected to my account. On the Home Assistant I'm getting the following error: image

I've tried to search the code but couldn't find anything related to captcha requests. Is there anything that I can check? Thanks

UPDATE: Did some more tests with the tokensaver.py script and it seems that somehow the login needs to accept a captcha.

STATE: XZrs8qZQlTR7SBRPfY5AyZXP7gk05_VgSMTOIf2AOTU
VERSION: 12785-3-27378195
LOGIN REPLY: {'callId': '4259bbd717304a85b34ac0f97d2a5022', 'errorCode': 401020, 'errorDetails': 'Login Failed Captcha Required', 'errorMessage': 'Login Failed Captcha Required', 'apiVersion': 2, 'statusCode': 401, 'statusReason': 'Unauthorized', 'time': '2022-01-20T15:38:31.644Z', 'errorFlags': 'captchaNeeded'}
Traceback (most recent call last):
  File "/Users/silvaric/projects/GIT/daikin_residential/tools/tokensaver.py", line 308, in retrieveAccessToken
    raise Exception('Unknown Login error: ' + response['errorDetails'] )
Exception: Unknown Login error: Login Failed Captcha Required

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/silvaric/projects/GIT/daikin_residential/tools/tokensaver.py", line 479, in <module>
    asyncio.run(main())
  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/local/Cellar/python@3.9/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/Users/silvaric/projects/GIT/daikin_residential/tools/tokensaver.py", line 467, in main
    tokenSet = await controller.retrieveAccessToken(user, pwd)
  File "/Users/silvaric/projects/GIT/daikin_residential/tools/tokensaver.py", line 310, in retrieveAccessToken
    raise Exception('Login failed')
Exception: Login failed

Is there any possibility to integrate that into the UI?

rospogrigio commented 2 years ago

Mmmm... we were afraid something like this could happen, sooner or later. Maybe you can try logging in from the Daikin app or using a browser on a PC and see if after you passed the captcha check the tokensaver works? If it does not, we are in big trouble because the integration would probably stop working very soon, and I don't really know how we can overcome this.

rospogrigio commented 2 years ago

I tried the tokensaver myself, and it worked without asking for a captcha. Maybe it's just a one-time-operation you need to perform, try to login to the app or to your web account and see if it solves the issue. Fingers crossed... 🤞

ricardojdsilva87 commented 2 years ago

Tried to logout and login again from the app but I'm still getting the same request the captcha... The app redirects me to a website id.daikin.eu, but it seems to me that it's a temporary redirect that acts as a login server. If I try to go there directly there is no option to login with the gmail credentials, it seems that is some kind of backoffice for companies. Do you know where to login via web? Thanks

ricardojdsilva87 commented 2 years ago

Just an update. It seems that the code should already enable the captcha check based on the body request:

BODY: // ### server injected code ###
var gigya = window.gigya;
if (typeof gigya == 'undefined' || !gigya.isGigya) {
    gigya = {isGigya: true};
}
gigya.apiKey = '3_xRB3jaQ62bVjqXU1omaEsPDVYC0Twi1zfq1zHPu_5HFT0zWkDvZJS97Yw1loJnTm';
gigya.defaultApiDomain = 'gigya.com';
gigya.dataCenter = 'eu1';
gigya.build = {
  "number": 12785,
  "version": "latest"
};
gigya.gmidVersion = 'ver4';

if (typeof gigya.partnerSettings == 'undefined') {
    gigya.partnerSettings = {
  "authMode": "cookie",
  "globalConf": "{\n    // A comma-delimited list of provider names to enable.\n    enabledProviders: '*',\n\n    // Define the language of Gigya's user interface and error message.\n    lang: 'en',\n    containerID: 'container',\n    authFlow: 'redirect',\n    \n    // Bind globally to events.\n    // See: http://developers.gigya.com/display/GD/Events#Events-OverridingtheDefaultEventMap\n    customEventMap: {\n        eventMap: [{\n            events: '*',\n            args: [function(e) {\n                return e;\n            }],\n            method: function(e) {\n                if (e.fullEventName === 'login') {\n                    // Handle login event here.\n                } else if (e.fullEventName === 'logout') {\n                    // Handle logout event here.\n                }\n            }\n        }]\n    }\n}",
  "captchaProvider": "Google",
  "siteGroupGlobalConf": "{\n    // A comma-delimited list of provider names to enable.\n    enabledProviders: '*',\n\n    // Define the language of Gigya's user interface and error message.\n    lang: 'en',\n    storageDomainOverride: 'cdc.daikin.eu',\n    \n    // Bind globally to events.\n    // See: http://developers.gigya.com/display/GD/Events#Events-OverridingtheDefaultEventMap\n    customEventMap: {\n        eventMap: [{\n            events: '*',\n            args: [function(e) {\n                return e;\n            }],\n            method: function(e) {\n                if (e.fullEventName === 'login') {\n                    // Handle login event here.\n                } else if (e.fullEventName === 'logout') {\n                    // Handle logout event here.\n                }\n            }\n        }]\n    }\n}",
  "recaptchaV2": {
    "siteKey": "6Lc-ebkUAAAAAGSmtZU4P3uC4MeiSQUbVR7bDgXy"
  },
  "plugins": {
    "connectWithoutLoginBehavior": "alwaysLogin",
    "defaultRegScreenSet": "Default-RegistrationLogin",
    "defaultMobileRegScreenSet": "Default-RegistrationLogin",
    "sessionExpiration": -2,
    "rememberSessionExpiration": 0,
    "apiDomain": "eu1.gigya.com"
  },
  "ssoKey": "3_QebFXhxEWDc8JhJdBWmvUd1e0AaWJCISbqe4QIHrk_KzNVJFJ4xsJ2UZbl8OIIFY",
  "baseDomains": "daikin.eu",
  "customAPIDomainPrefix": "cdc"
};
}
gigya.providersConfig = {
  "facebook": {
    "appID": "548543762554249",
    "version": "v2.0"
  },
  "googlePlus": {
    "clientId": "1064858507908-5i1n5s67fc2v4mfo31ki7pkrvk1fofkk.apps.googleusercontent.com",
    "scopes": "profile email"
  }
};
gigya.samlConfig = {
  "errorPageURL": "https://my.daikin.eu/content/daikinid-cdc-saml/en/error.html",
  "proxyPageURL": "https://my.daikin.eu/content/daikinid-cdc-saml/en/proxy.html"
};
gigya.canary = gigya.canary || { isActive: false, config: {
  "version": "12785-3-27379395",
  "isEnabled": true,
  "probability": 3,
  "cookiesNames": {
    "isCanary": "gig_canary",
    "version": "gig_canary_ver"
  }
} };
gigya.errorReport = {
  "enabled": true,
  "probability": 1
};
gigya.gmidVersion = 'ver4';
gigya.bypassCaptchaV1 = true;
if (gigya.canary && gigya.canary.isActive) {} else if (gigya.__initialized) { console.warn('**** gigya.js loaded twice ****'); }
else {
gigya.__initialized = true;
}

I have removed the last part about the license it was code printed and it was heavy to paste here. For what I see the code enables the captcha check using google (the login method I'm using). Not sure if this helps Thanks

rospogrigio commented 2 years ago

...maybe if you register normally instead of using google to login?

ricardojdsilva87 commented 2 years ago

Hello again, just to leave the workaround I've done to make the integration work in HA. I'm still using the google login as the primary login on my phone for example, but created a new account for the HA to work: Google login email - email@gmail.com new login - email+1@gmail.com --> This way you will still receive the confirmation email without the need to create a new email address. Create the account here: https://my.daikin.eu/content/daikinid-cdc-saml/en/login.html

After that I've just shared the home where I had previously added the devices with this new account via the generated QR code. After this I've just added the integration with the new email and password in HA.

@rospogrigio thanks for all the help and for integration :)