shenxn / ha-dyson-cloud

Cloud integration for ha-dyson (https://github.com/shenxn/ha-dyson/)
MIT License
33 stars 20 forks source link

Unable to auth via cloud #6

Open troykelly opened 3 years ago

troykelly commented 3 years ago

Receiving the error below (with a correct email address)

Screen Shot 2021-07-11 at 10 03 23 pm
Logger: aiohttp.server
Source: custom_components/dyson_cloud/config_flow.py:71
Integration: dyson_cloud (documentation, issues)
First occurred: 10:00:31 PM (3 occurrences)
Last logged: 10:00:54 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 119, 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 197, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 24, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 78, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 144, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 135, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 155, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 63, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 109, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 202, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 260, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/dyson_cloud/config_flow.py", line 71, in async_step_email
    self._verify = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.9/site-packages/libdyson/cloud/account.py", line 127, in login_email_otp
    response = self.request(
  File "/usr/local/lib/python3.9/site-packages/libdyson/cloud/account.py", line 119, in request
    raise DysonInvalidAuth
libdyson.exceptions.DysonInvalidAuth
shenxn commented 3 years ago

Yes this has something to do with changes in Dyson API. I'm a little busy recently. It'll be good if someone can somehow find out how the new login process works.

kintaroju commented 3 years ago

gotta hate it when dyson changes the login process again, this is like the 2nd time they did this within this year.

blairscarlett commented 2 years ago

I just installed this addon and am having the same authentication issue with the Cloud

grahambish commented 2 years ago

Getting the same error trying to set up Dyson Cloud too 😞 They keep changing that login api a lot.

micahqcade commented 1 year ago

I think I found a fix, the Dyson login changed, and requires a "2FAish" setup where they send you a code and then you use your password and code to sign. Log out of the mobile app, close the app, then log back in using the code provided. I did that and my integration was able to login automatically without me manually logging on . I found this answer in a different dyson repository. I guess their 2FA is a one time thing

dotvezz commented 1 year ago

For anyone still dealing with this Dyson login issue, I've got a fix implemented over in a PR over here: https://github.com/libdyson-wg/libdyson-neon/pull/6. If anyone wants to help test it, you can clone https://github.com/dotvezz/libdyson-neon/tree/task/fix-account-login and run the get_devices.py script!

Short version I did some reverse-engineering of the Android mobile app. I discovered a mysterious GET request it was making to a provisioning API. Turns out, just by making that request (and even throwing away its response - no session tokens or cookies to hold onto), it unlocks something on the server side, and allows the rest of the ogin requests from your IP address. I've included more thoughts about this in the code comments and PR description for anyone who is curious.

If it proves robust enough in testing, I'll get it merged and tag a new release of https://github.com/libdyson-wg/ha-dyson-cloud to use the updated new login flow. To use it, you'll need to migrate to the new repositories in your HACS setup, there's a simple how-to in the readme here: https://github.com/libdyson-wg/ha-dyson#migration-from-shenxnha-dyson. Users have reported painless migrations so far!

Quick edit: For anyone curious about the "libdyson-wg" organization those new repositories are on, feel free to check out #20 for more information!