Skip to content

Fix Apple SMS 2FA verification failing with 'Invalid security code'#158

Merged
Redth merged 1 commit intomainfrom
redth/fix-apple-sms-2fa-verification
Apr 21, 2026
Merged

Fix Apple SMS 2FA verification failing with 'Invalid security code'#158
Redth merged 1 commit intomainfrom
redth/fix-apple-sms-2fa-verification

Conversation

@Redth
Copy link
Copy Markdown
Owner

@Redth Redth commented Apr 21, 2026

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:

  1. SMS codes sent to wrong endpoint — For hsa2 accounts, CanUseTrustedDevice is always true (even with no trusted devices), so the code defaulted to the /verify/trusteddevice/securitycode endpoint instead of /verify/phone/securitycode.

  2. 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.

  3. RequestSmsCodeAsync never called from UI — When SMS was selected (or auto-selected), the app never called PUT /verify/phone to trigger Apple to actually send the SMS. The method existed but was unused.

  4. RequestSmsCodeAsync missing session headers — Even if called, it didn't include the required X-Apple-ID-Session-Id / scnt headers, so Apple would reject the request.

Fix

  • Show the verification method dropdown whenever there are any phone numbers (≥ 1, not > 1)
  • Call RequestSmsCodeAsync when a phone is selected (either auto-selected on transition to 2FA step, or manually switched by user)
  • Add session headers and use cached service key in RequestSmsCodeAsync

Files Changed

  • src/MauiSherpa.Core/Services/AppleDownloadAuthService.cs — Fix RequestSmsCodeAsync session headers
  • src/MauiSherpa/Pages/Modals/XcodeDownloadAuthModal.razor — Fix dropdown visibility, trigger SMS delivery

Fixes #157

- 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>
@Redth Redth merged commit 0a19409 into main Apr 21, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to login into Apple Developer account

1 participant