cjaliaga / aioaquarea

Asynchronous library to control Panasonic Aquarea devices
MIT License
11 stars 4 forks source link

auth api failing with 1000-0999 error #44

Open viliusdidit opened 4 months ago

viliusdidit commented 4 months ago

March 18 around 00 UTC authentication to aquarea-smart.panasonic.com started failing. likely due to API change?

https://github.com/cjaliaga/home-assistant-aquarea/issues/105

I believe our connection string looks like this? any request to this enpoint seems to result in the same error/403:

curl -H "Content-Type: application/x-www-form-urlencoded" 
-H "Cache-Control: max-age=0" 
-H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" 
-H "Accept-Encoding: deflate, br" -H "Upgrade-Insecure-Requests: 1" 
-H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0" 
-X POST 'https://aquarea-smart.panasonic.com/remote/v1/api/auth/login?username=panasonic@xxxx&password=xxxxx'

{"errorCode":4194816,"message":[{"errorMessage":"Logged out due to system error. Please login again after a while.","errorCode":"1000-0999","additionalErrorCode":null}],"accessToken":{}}

FWIW - I was able to see web login process to https://authglb.digital.panasonic.com/usernamepassword/login, don't have a setup for sniff the mobile app atm:

<client_id>vf2i6hW5hA2BB2BQGfTHXM4YFyW4I06K</client_id>
<redirect_uri>https://aquarea-smart.panasonic.com/authorizationCallback?lang=en</redirect_uri>
<tenant>pdpauthglb-a1</tenant>
<response_type>code</response_type>
<scope>openid offline_access</scope>
<audience>https://digital.panasonic.com/vf2i6hW5hA2BB2BQGfTHXM4YFyW4I06K/api/v1/</audience>
<_csrf>9OCkcl4F-fgQCE4wTTDWTMQnIHnO-Ek1wBlk</_csrf>
<state>hKFo2SAweUM4X0tybnhUNmZtSUZVdTlfTFVkdjQwZ0Z4TWJHeKFupWxvZ2luo3RpZNkgOG9rMzZOVkNjemJkRlN2a0J1YkN3OHdyczZ3S2RJTmOjY2lk2SB2ZjJpNmhXNWhBMkJCMkJRR2ZUSFhNNFlGeVc0STA2Sxx</state>
<_intstate>deprecated</_intstate>
<username>Panasonic@xxx</username>
<password>xxxx</password>
<lang>en</lang>
<connection>PanasonicID-Authentication</connection>
viliusdidit commented 4 months ago

my attempts to generate/guess/reuse state param for authglb endpoint fail with this error: {"statusCode":403,"description":"Invalid state","name":"AnomalyDetected","code":"access_denied"}

anyone out there more familiar with this oauth2 aspect? or is it some kind of secret authglb is expecting to be encoded in the state? fwiw, there was no forced upgrade on mobile app side, Dec 2023 still works with this auth.

snaow commented 4 months ago

Same error happening here. I saw that on Native Panasonic Cloud app there was a new "policy" notes to be accepted.

Thanks.

viliusdidit commented 4 months ago

the good news: this new authglb seems to allow multiple logins. at least when using google login which is an option now (apple id as well; need to register here - https://accountglb.digital.panasonic.com/social first)

cjaliaga commented 4 months ago

Thanks @viliusdidit for all the investigation so far, let's see what we can do. The ideal (in a happy world) solution would be for us to not need to use the username and password and being able to auth as a service/application to Panasonic cloud, get a token, and use that token, with the possibility of getting a refresh_token as well. Unfortunately I don't see that happening.

denisbobovnik commented 4 months ago

Thanks @viliusdidit for all the investigation so far, let's see what we can do. The ideal (in a happy world) solution would be for us to not need to use the username and password and being able to auth as a service/application to Panasonic cloud, get a token, and use that token, with the possibility of getting a refresh_token as well. Unfortunately I don't see that happening.

hopefully you can make it happen for all of us somehow šŸ™Œ

afharo commented 4 months ago

In case it helps, I noticed this NPM library that takes a different approach: it "impersonates" the iOS app using a different set of APIs.

Just sharing due to the lack of public documentation from Panasonic around their APIs.

bimusiek commented 3 months ago

Hey guys, I found your issue by searching if someone fixed the new login way to Panasonic Cloud. As nobody did, here is the working code: https://github.com/Hernas/homebridge-panasonic-heat-pump/commit/dd04fc2b7a207a2648d7ad94bb8eb19052d21bf2

I hope that helps! :)

cjaliaga commented 3 months ago

Thanks a lot @bimusiek, I'll take a look ASAP.

lcavalli commented 3 months ago

@cjaliaga, I have seen that the fix has been implemented in dedicated branch. I don't know if there are some technical issues to be solved, but if you are afraid of exposing the hard-coded client id, maybe it can be provided by the user during the integration config flow.

bimusiek commented 3 months ago

The clientId was copied from JS code of OAuth provider at Panasonic so you could fetch it from there. AFAIK it is Panasonic client id from their oauth provider so it is not secret and should not change.

cjaliaga commented 3 months ago

Thanks @lcavalli, as @bimusiek said this Client Id it's not a secret and shouldn't change. Thanks for stepping in šŸ˜Š

I'm implementing it on this branch: https://github.com/cjaliaga/aioaquarea/blob/7ddd0eac009a23a4b60aea42f20eb36c773281f6/aioaquarea/core.py#L349

To give an update, I'm currently stuck on the response 3 (call with the username and password to https://authglb.digital.panasonic.com/usernamepassword/login). I'll need to check if I'm not sending all the required cookies, the json sent with aiohttp is not properly encoded, something else.. or there's something wrong with my username because the response I get from the endpoint is a Bad Request - 400 invalid username

I'll check with @bimusiek project and my username/password to discard that.

cjaliaga commented 3 months ago

Quick update, it was a silly mistake. Apologies on the slow pace as I'm doing my best mainly on the night on the few spare minutes I have this week, I'm exhausted at the end of the day and I end making this mistakes haha.

My estimation is to have a working solution tomorrow for everyone to test it.

randriese commented 3 months ago

Quick update, it was a silly mistake. Apologies on the slow pace as I'm doing my best mainly on the night on the few spare minutes I have this week, I'm exhausted at the end of the day and I end making this mistakes haha.

My estimation is to have a working solution tomorrow for everyone to test it.

Don't worry, we appreciate your efforts!

snaow commented 3 months ago

Thanks @cjaliaga !!

cjaliaga commented 3 months ago

I have a working version, and I'm sure it will require some refactor but I think the best way is for us to test it and find the edge cases (and maybe not that edge haha) while using it so I'll release a new version with the changes.

jp-embedded commented 3 months ago

I am getting this:

'<' not supported between instances of 'datetime.datetime' and 'NoneType' Cannot connect to host authglb.digital.panasonic.comhttps:443 ssl:default [Name or service not known] Cannot connect to host authglb.digital.panasonic.comhttps:443 ssl:default [Name or service not known] Cannot connect to host authglb.digital.panasonic.comhttps:443 ssl:default [Name or service not known] Cannot connect to host authglb.digital.panasonic.comhttps:443 ssl:default [Name or service not known] Cannot connect to host authglb.digital.panasonic.comhttps:443 ssl:default [Name or service not known] Cannot connect to host authglb.digital.panasonic.comhttps:443 ssl:default [Name or service not known]

cjaliaga commented 3 months ago

@jp-embedded the first error should have been fixed in 0.7.1

The other ones authglb.digital.panasonic.comhttps:443 ssl:default [Name or service not known] Cannot connect to host I think are a result of some request failing breaking the auth flow, and hence the location header resolves to a full URL instead of a path, like here:

https://github.com/cjaliaga/aioaquarea/blob/a8562de53bf72e34a5dd9b246ce62987d6780bb4/aioaquarea/core.py#L299-L317

I'll add verifications in between requests and more logging soon.

jp-embedded commented 3 months ago

0.7.1 works for me. Thank you so much <3

vukisz commented 3 months ago

Thanks. Fix was faster then heishamon delivery. Just one issue for me: After around 24 hours of updating all entities turned unavailable. Reloading integration fixed it

CofkoCof commented 3 months ago

Same issue happened to me as it did for @vukisz. Entities were unavailable until I reloaded the integration. Now is working fine.

snaow commented 3 months ago

Working! Thanks!

cjaliaga commented 3 months ago

I have a theory about why it didn't try to refresh the data, I think is due to token expiratio and some assumption I took for granted. I'll try to release a hotfix later today.

cjaliaga commented 3 months ago

Just merged #47 that should fix the refresh issue. Publishing 0.7.2 with the fix.

steinbuyle commented 3 months ago

0.7.1 works fine for me. Thanks for the work you've put into!