fix: trigger 2FA push notification after SRP authentication#260
Conversation
After SRP /signin/complete raises PyiCloud2FARequiredException, pyicloud retrieved auth options via GET /appleauth/auth but never explicitly requested delivery of the verification code. Apple does not auto-push for API-based (non-browser) sessions, so users received no code on their trusted devices. Add _request_2fa_code() which calls GET /verify/trusteddevice to trigger the push notification and falls back to PUT /verify/phone (SMS) when a trusted phone number is available. Call it automatically from _srp_authentication() after _get_mfa_auth_options() sets _auth_data. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummary by CodeRabbitRelease Notes
WalkthroughThis PR adds explicit 2FA code delivery for SRP-based authentication. When a sign-in attempt requires 2FA, the code now calls a new Changes2FA Code Delivery for SRP Authentication
Sequence DiagramsequenceDiagram
participant SRPAuth as SRP Auth Handler
participant RequestMethod as _request_2fa_code()
participant TrustedDeviceAPI as Trusted-Device Push
participant SMSAPI as SMS Verify Phone
RequestMethod->>TrustedDeviceAPI: GET /verify/trusteddevice<br/>(with Accept: application/json)
alt Push succeeds
TrustedDeviceAPI-->>RequestMethod: Push sent
else Push fails
TrustedDeviceAPI-->>RequestMethod: Request error
RequestMethod->>SMSAPI: PUT /verify/phone<br/>(phoneId + mode: sms)
SMSAPI-->>RequestMethod: SMS sent or error logged
end
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly Related PRs
Suggested Labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Pylint (4.0.5)pyicloud/base.pyTraceback (most recent call last): tests/test_base.pyTraceback (most recent call last): Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@TeroPihlaja many thanks for your support and contribution |
Problem
After SRP
/signin/completeraisesPyiCloud2FARequiredException, pyicloud calls_get_mfa_auth_options()to retrieve auth options but never explicitly requests delivery of the verification code.Apple does not automatically push a code to the user's trusted devices for API-based (non-browser) sessions. As a result, users waiting for the 6-digit code on their iPhone/Mac receive nothing — authentication stalls indefinitely.
This was observed with a real Apple ID password on an HSA2 account (the SRP path). The
GET /appleauth/authcall fetches the challenge parameters, but without an explicitGET /verify/trusteddevicecall, Apple's servers never trigger the device push.Fix
Add
_request_2fa_code()which:GET /verify/trusteddevice— explicitly triggers Apple to push the 6-digit code to all trusted devices (iPhone, Mac, etc.)PUT /verify/phone(SMS fallback) — requests an SMS code if a trusted phone number is present in_auth_dataCall it automatically from
_srp_authentication()immediately after_get_mfa_auth_options()populates_auth_data.Why not call the existing
request_2fa_code()?The public
request_2fa_code()routes through the trusted-device bridge (WebSocket) or SMS. When neither is available (no bridge boot context, no SMS mode reported), it returnsFalseand no code is delivered. TheGET /verify/trusteddeviceendpoint is the simpler, direct path to trigger the user-visible push notification independently of the bridge flow.Tests
Three new tests in
tests/test_base.py:test_private_request_2fa_code_triggers_trusted_device_push— verifies theGET /verify/trusteddevicecall is madetest_private_request_2fa_code_sends_sms_when_phone_available— verifies SMS fallback viaPUT /verify/phonetest_srp_authentication_calls_request_2fa_code_when_2fa_required— integration:_srp_authentication()invokes_request_2fa_code()when Apple signals 2FA required🤖 Generated with Claude Code