Fix 2FA authentication regression causing 403 on download (#480)#481
Merged
MattKiazyk merged 1 commit intoJun 17, 2026
Merged
Conversation
9e0fe9a to
bdaec97
Compare
In 1.6.x, Client.srpLogin drove the entire interactive two-factor flow internally and only returned once the session was fully authenticated. In 2.x, login moved to XcodesLoginKit and srpLogin now returns an AuthenticationState instead of completing the flow, expecting the caller to handle the second factor. The CLI's login closures discarded that state, so 2FA accounts were left with an unauthenticated (pre-2FA) cookie jar: no verification-code prompt appeared and downloads failed with 403 Unauthorized. Restore the interactive completion for the paths 1.6.x supported: trusted-device codes, SMS auto-sent, and SMS phone-number selection. Security-key and federated/not-developer states surface clear errors. The flow is modeled with injected closures (Dependencies) rather than a concrete Client to match the existing dependency-injection style and to keep it unit-testable. Adds coverage for each branch. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
bdaec97 to
3c5d5ed
Compare
Contributor
|
Thanks @kinoroy - I'll try to get this merged and built soon! |
MattKiazyk
approved these changes
Jun 17, 2026
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.
Summary
Fixes #480 — accounts with two-factor authentication get a
403: Unauthorizedon download because the CLI never completes the 2FA flow (no verification-code prompt appears).Root cause
In 1.6.x,
Client.srpLogindrove the entire interactive 2FA flow internally — on Apple's409response it prompted for the verification code, submitted it, trusted the session, and only returned once fully authenticated.In 2.x, login moved to the external
XcodesLoginKitpackage and was redesigned as a state machine.srpLoginnow returns anAuthenticationState(e.g..waitingForSecondFactor) instead of completing the flow — the caller is expected to drive the second factor (the SwiftUI app does this). But the CLI'sloginclosures inEnvironment.swiftdiscarded the returned state:So for any 2FA account:
srpLoginreturned.waitingForSecondFactorwithout throwing →AppleSessionService.loginIfNeededtreated it as success → the cookie jar held only the pre-2FA session → the download hit Apple's 403 Unauthorized. The missing 2FA prompt was the visible symptom; the 403 was the downstream consequence. Non-2FA accounts were unaffected, which matches the report that this is a regression specific to 2FA accounts.The fix
TwoFactorAuthentication.swift(new): Ports 1.6.x's interactive completion onto the new state-machine API.completeIfNeeded(_:dependencies:)inspects the returned state and handles every path 1.6.x supported:"sms"fallback to phone-number selection)Modeled with injected closures (
Dependencies) rather than the concreteClient, matching the repo's existing dependency-injection style and keeping it unit-testable.Environment.swift: Bothloginclosures now capture the returned state and callTwoFactorAuthentication.completeIfNeeded(...).TwoFactorAuthenticationTests.swift(new): 8 tests covering each branch.Testing
swift test— 87 passed, 0 failures (was 79; +8 new).xcodes installend-to-end against a real Apple ID with SMS 2FA and against one with trusted-device 2FA — both now prompt for the code and authenticate successfully.