Fix Apple SMS 2FA verification failing with 'Invalid security code'#158
Merged
Fix Apple SMS 2FA verification failing with 'Invalid security code'#158
Conversation
- Show verification method dropdown when any phone numbers exist (was > 1) so single-phone users can switch from Trusted Device to SMS - Call RequestSmsCodeAsync to trigger Apple to send the SMS when phone is selected (auto-selected or user-switched) — was never called from UI - Add session headers (X-Apple-ID-Session-Id, scnt) to RequestSmsCodeAsync and use cached service key — requests were failing without session context Fixes #157 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Users who receive Apple 2FA codes via SMS (rather than trusted device push) always get "Invalid security code" when verifying. Reported in #157.
Root Cause
Four interrelated bugs in the Apple 2FA flow:
SMS codes sent to wrong endpoint — For hsa2 accounts,
CanUseTrustedDeviceis alwaystrue(even with no trusted devices), so the code defaulted to the/verify/trusteddevice/securitycodeendpoint instead of/verify/phone/securitycode.Phone dropdown hidden for single-phone users — The verification method dropdown only showed when
TrustedPhoneNumbers.Count > 1, so users with one phone number couldn't switch from "Trusted Device" to SMS.RequestSmsCodeAsyncnever called from UI — When SMS was selected (or auto-selected), the app never calledPUT /verify/phoneto trigger Apple to actually send the SMS. The method existed but was unused.RequestSmsCodeAsyncmissing session headers — Even if called, it didn't include the requiredX-Apple-ID-Session-Id/scntheaders, so Apple would reject the request.Fix
RequestSmsCodeAsyncwhen a phone is selected (either auto-selected on transition to 2FA step, or manually switched by user)RequestSmsCodeAsyncFiles Changed
src/MauiSherpa.Core/Services/AppleDownloadAuthService.cs— FixRequestSmsCodeAsyncsession headerssrc/MauiSherpa/Pages/Modals/XcodeDownloadAuthModal.razor— Fix dropdown visibility, trigger SMS deliveryFixes #157