gcobb321 / icloud3

iCloud3 v3 - iCloud3 is an advanced iDevice tracker that uses Apple iCloud account and HA Companion App data for presence detection and location based automations.
MIT License
581 stars 54 forks source link

Doesn't receive two step Account Authentication Configurator #211

Closed vig0r closed 2 years ago

vig0r commented 2 years ago

I can't receive the two step Account Authentication Configurator. It didn't appear in the notice column. I tried to modify the domain name in pyicloud_ic3.py ,changed the domain name of HOME_ENDPOINT to "https://www.icloud.com.cn", I clould receive the step Account Authentication Configuratorm, and it appeared in the notice column. But the location was incorrect.

gcobb321 commented 2 years ago

You can reset the iCloud session using Event Log > Actions > Reset iCloud Interface. This will delete the cookies and session files and will then ask for a new 2-fa code using the window opened on the HA Notifications screen.

vig0r commented 2 years ago

I used to be able to use it normally, but now I have the above problem after restrating homeassistant. I also followed the documentation to clear cookies , reinstall the HA, copy the new file pyicloud_ic3.py v3.0.0,unfortunately the problem was not resolved. Maybe it's because I have upgraded my iphone to IOS 15.4.1.

gcobb321 commented 2 years ago

I’m running iOS 15.4.1 and doing fine. In the file with your iCloud3 configuration, add log_level: debug+rawdata and restart iCloud3. In the home_asstsiant.log file, Look for the REQUEST and RESPONSE requests from iCloud. The response code is 200 if everything is ok and 421, 450 or 500 is an authorization is needed.

gcobb321 commented 2 years ago

Also make sure you aren’t getting any other errors coming from pyicloud_ic3 or iCloud3. That version has a lot of code to support the next release of iCloud3 and has not been through a lot of testing when using iCloud3 v2.4.7.

vig0r commented 2 years ago

Error Logger: custom_components.icloud3.device_tracker Source: custom_components/icloud3/device_tracker.py:9139 Integration: icloud3 (documentation, issues) First occurred: 21:20:45 (1 occurrences) Last logged: 21:20:45

iCloud3 Error > An error was encountered setting up the pyicloud_ic3.py module. Either the module was not found or there was an error loading it.The iCloud Location Service is disabled and the iOS App tracking_method will be used.

gcobb321 commented 2 years ago

Reinstall iCloud3 from HACS or, reinstall the previous pyicloud_ic3.py (if you saved the old version) and restart HA to get back to where you were. Then try the log_level statement above to see if that points to anything.

I assume you have logged into your iCloud account with another app or program and verified the username/password.

vig0r commented 2 years ago

2022-04-07 22:35:05 INFO (SyncWorker_8) [custom_components.icloud3.device_tracker] Stage 2a > Authenticate iCloud Account, List Trackable Devices 2022-04-07 22:35:05 INFO (SyncWorker_8) [custom_components.icloud3.device_tracker] iCloud Web Services interface (pyicloud_ic3.py) > Verified 2022-04-07 22:35:05 INFO (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3] Session file does not exist 2022-04-07 22:35:05 INFO (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3] Authenticating account xxxxx@icloud.com using Account/PasswordSignin 2022-04-07 22:35:05 DEBUG (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3.http] REQUEST -- 22:35:05, POST, https://idmsa.apple.com/appleauth/auth/signin, {"accountName": "xxxxxxx@icloud.com", "password": "****", "rememberMe": true, "trustTokens": []} 2022-04-07 22:35:06 DEBUG (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3.http] RESPONSE -- <Response [200]>, StatusCode-200, okStatus-True, hasRetried-False 2022-04-07 22:35:06 DEBUG (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3] RESPONSE DATA -- None 2022-04-07 22:35:06 DEBUG (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3] Session saved to /config/.storage/icloud/session/xxxxicloudcom 2022-04-07 22:35:06 DEBUG (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3] Cookies saved to /config/.storage/icloud/xxxxddicloudcom 2022-04-07 22:35:06 DEBUG (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3.http] REQUEST -- 22:35:06, POST, https://setup.icloud.com/setup/ws/1/accountLogin?clientBuildNumber=2021Project52&clientMasteringNumber=xxxxxxxxxxxx&clientId=xxxxxxxxxx , {"accountCountryCode": "CHN", "dsWebAuthToken": "xxxdxxdxxxxxxxxxx==", "extended_login": true, "trustToken": ""} 2022-04-07 22:35:08 DEBUG (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3.http] RESPONSE -- <Response [302]>, StatusCode-302, okStatus-True, hasRetried-False 2022-04-07 22:35:08 DEBUG (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3] RESPONSE CONTENT_TYPE -- application/json 2022-04-07 22:35:08 DEBUG (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3] RESPONSE INVALID CONTENT TYPE -- False 2022-04-07 22:35:08 DEBUG (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3] RESPONSE HEADERS -- {'Server': 'AppleHttpServer/f51b8f44eee0', 'Date': 'Thu, 07 Apr 2022 14:35:08 GMT', 'Content-Type': 'application/json; charset=UTF-8', 'Content-Length': '51', 'Connection': 'keep-alive', 'X-Apple-Jingle-Correlation-Key': 'xxxxxxxxU', 'apple-seq': '0', 'apple-tk': 'false', 'Apple-Originating-System': 'UnknownOriginatingSystem', 'X-Responding-Instance': 'setupservice:xxxxxxxxxxx4', 'Cache-Control': 'no-cache, no-store, private', 'Access-Control-Allow-Origin': 'https://www.icloud.com', 'Access-Control-Allow-Credentials': 'true', 'content-encoding': 'gzip', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains', 'x-apple-user-partition': '21', 'via': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'X-Apple-Request-UUID': 'xxxxxxxxxxxxxxx', 'access-control-expose-headers': 'X-Apple-Request-UUID,Via', 'X-Apple-Edge-Response-Time': '1483'} 2022-04-07 22:35:08 DEBUG (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3] RESPONSE DATA -- {'domainToUse': 'iCloud.com.cn'} 2022-04-07 22:35:08 DEBUG (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3] Session saved to /config/.storage/icloud/session/xxxxxicloudcom 2022-04-07 22:35:08 DEBUG (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3] Cookies saved to /config/.storage/icloud/xxxxxxicloudcom 2022-04-07 22:35:08 ERROR (SyncWorker_8) [custom_components.icloud3.device_tracker] 'webservices'

gcobb321 commented 2 years ago

2022-04-07 22:35:08 DEBUG (SyncWorker_8) [custom_components.icloud3.pyicloud_ic3.http] RESPONSE -- <Response [302]>, StatusCode-302, okStatus-True, hasRetried-False

The StatusCode-302 indicates some type of error being returned from Apple. I did a quick google and saw one posting that said it has to do with an invalid redirect.

This problem has something to do with accessing iCloud and that is what you will need to investigate. From what I can tell, it does not appear to be an iCloud3 issue, other than iCloud3 could supply a better error message. Other than that, I won't be able to help you determine what is going on.

vig0r commented 2 years ago

I couldn't login my appleID at https://www.icloud.com/, but the page prompted me to login at https://www.icloud.com.cn/. So I tried to modify the file pyicloud_ic3.py, change the text HOME_ENDPOINT ="https://www.icloud.com" to HOME_ENDPOINT ="https://www.icloud.com.cn", I clould receive the step Account Authentication Configuratorm, and it appeared in the notice column. but the location was incorrect. I think the appleID maybe use the different domain to login in different regions. Thanks

Xavier9896 commented 2 years ago

I filed the same issue in another issues https://github.com/gcobb321/icloud3/issues/207#issuecomment-1086043091. I think it should be that Apple has modified the login server for China, but it is not clear whether the login process and verification in China are consistent with other regions. At least simply modifying HOME_ENDPOINT and SETUP_ENDPOINT in pyicloud_ic3.py to .com.cn will not work. (I checked in the browser console that AUTH_ENDPOINT does not need to be modified). --Translated from Google

vig0r commented 2 years ago

It has been solved temporarily by modifying pyicloud_ic3.py. Thanks

Xavier9896 commented 2 years ago

It has been solved temporarily by modifying pyicloud_ic3.py. Thanks

@vig0r 兄弟,你怎么解决问题的?之前的2.4.7版本我就发现了是域名的问题,修改了HOME_ENDPOINTSETUP_ENDPOINT却并不生效。昨晚我在3.0版修改这两个还是有相同的问题。

Bro, how did you solve the problem? In the previous version 2.4.7, I found out that it was a domain name problem, and the modification of HOME_ENDPOINT and SETUP_ENDPOINT did not take effect. Last night I modified these two in version 3.0 and still had the same problem. --Translated from Google

vig0r commented 2 years ago

我也是修改的HOME_ENDPOINT和SETUP_ENDPOINT,3.0没有尝试。

So do I,this problem can be solved by modify the file pyicloud_ic3.py.

Xavier9896 commented 2 years ago

修改这两个的域名后缀为.com.cn就行了吗?其他啥都不用改?我想可能我得清除一下session试试。 感谢,我去试试。🙏 翻译自谷歌

Is it enough to modify the domain name suffixes of these two to .com.cn? Nothing else to change? I think maybe I have to clear the session and try. Thanks, I'll try it. 🙏 --Translated from Google

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年4月13日(星期三) 中午11:07 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [gcobb321/icloud3] Doesn't receive two step Account Authentication Configurator (Issue #211)

我也是修改的HOME_ENDPOINT和SETUP_ENDPOINT,3.0没有尝试。

So do I,this problem can be solved by modify the file pyicloud_ic3.py.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

Xavier9896 commented 2 years ago

@vig0r 我试了下还是不行,可以麻烦你把 custom_components/icloud3 打包发给我吗? admin@54xavier.cn

vig0r commented 2 years ago

已经通过邮箱发你了,可否使用?

Xavier9896 commented 2 years ago

谢谢,昨晚已经接收到了,我把icloud3放到了homeassistant/custom_components下,清除了session,重启了homeassistant,还是不行,反而我美区的appleID居然可以登录。所以我怀疑是不是文件没有更新到,用configurator看了下,域名地址又是改到了的,有点儿迷。

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年4月14日(星期四) 上午10:12 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [gcobb321/icloud3] Doesn't receive two step Account Authentication Configurator (Issue #211)

已经通过邮箱发你了,可否使用?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

gcobb321 commented 2 years ago

@vig0r @Xavier9896

I have added code to extract the country code from HA when starting up and to enter it into the iCloud3 configuration file when the file is first initialized. That code is then added to the url's to access to the iCloud account during authentication and when getting location data.

The code in pyicloud_ic3.py now reads:

HOME_ENDPOINT = "https://www.icloud.com.cn"
SETUP_ENDPOINT = "https://setup.icloud.com.cn/setup/ws/1"

Can you verify that these changes are correct and no other changes need to be made.

Thanks.

Gary

vig0r commented 2 years ago

With the modification, it works.