Repository navigation
feat(auth): sign in and sign out through v2 - #359
Conversation
|
Warning Review limit reachedNext included review available in 9 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (10)
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 |
There was a problem hiding this comment.
Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code review summaryReviewed head: Process: an adversarial review of this PR's diff with each candidate finding independently verified before any fix, a simplify pass for medium and larger PRs, and a whole-stack review across contract conformance, authority and failure handling, data integrity, user-visible behavior and cross-PR integration. Verified findings, all fixed on this branch:
Validation: this branch builds on its own for iOS, tvOS and macOS, and its focused tests passed. The completed stack passed the full iOS suite (1981 tests) and tvOS suite (1792 tests) with 0 failures, the macOS build and the v1 path guard. The final stack was also exercised on iOS and tvOS simulators against a v1/v2 bridge server: sign-in (password and QR), restore, browse, search, detail, favorites and watchlist, playback (direct play, transcode, subtitles, stop), audiobooks, downloads with offline playback, settings, requests, profiles, push registration and diagnostics. Server logs showed no Remaining: no open verified findings. Merge in stack order. Mergeability: 8/10 — conditional. The approach holds up and every verified finding is fixed. Conditions: this PR's CI must pass (it was pending at review time), and the owner still plans a physical-device check of the completed stack. Review by Claude Opus 5.5 ( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 78cd1d21e3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "/api/v1/auth/logout", | ||
| // Best effort: the temporary session expires server-side when the | ||
| // revoke is refused, fails, or is skipped for a v1-only server. | ||
| try? await SiloAPI.shared.apiV2Client.logout( |
There was a problem hiding this comment.
Gate temporary logout against its own server
When SiloRemote is using a different server from the saved active server, this call still enters APIv2Client.gate(), whose default verdict is ConnectionMonitor.isServerUpdateRequired for the registry's active server rather than scope.serverId. If the saved server is marked v1-only while the temporary server supports v2, ending remote playback skips the logout and leaves that temporary server session valid until expiry. Bypass the unrelated global gate here or evaluate the contract verdict for the temporary scope's server.
Useful? React with 👍 / 👎.
78cd1d2 to
62dfb06
Compare
05908e5 to
5d7ac1b
Compare
Password sign-in still posted to /api/v1/auth/login, and both sign-out revocations posted to /api/v1/auth/logout. A 1.0 server answers every v1 path except health with 410, so these calls would stop working. The v1 login answer also carried an integer user id that the app never bound, so a fresh sign-in left the session without a verified account. AuthService.login now calls APIv2Client.login (POST /api/v2/auth/login) and installs the session with TokenPair.user.id as its verified account id. The QR sign-in keeps an unverified binding until it moves to v2. LoginViewModel maps v2 problem statuses (401, 403, 400/422, 429) to form copy and shows the existing update messages for a v1-only server or a 410 client_upgrade_required answer. Sign-out stays local-first: HTTPClient.revokeSession only changes its path to /api/v2/auth/logout and still sends just the captured bearer. The SiloRemote temporary scope on tvOS now ends through APIv2Client.logout. HTTPClient.requestData gains sendsProfile so that call drops X-Profile-Id and X-Profile-Token, which v2 logout does not accept, including on the resend after a token refresh. The unused v1 LoginResponse model is deleted. Stack-PR: W5-A Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A proxy or WAF in front of the server can answer the v2 login with a 401 or 403 and a non-problem body. The login form mapped those bare statuses to "Incorrect username or password." or the account-disabled copy, even though Silo's login only rejects with problem documents. Map 401, 403, 400 and 422 only for problem documents. A bare 429 still reads as rate limiting; other bare statuses show the generic HTTP text. Stack-PR: W5-A Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
62dfb06 to
ca3214f
Compare
Password sign-in and both sign-out revocations now use
/api/v2. A fresh sign-in also binds the session to the account id the server returns.Problem
AuthService.loginposted to/api/v1/auth/login(inventory row 3).HTTPClient.revokeSession(row 4) and the tvOS SiloRemoteRemotePlaybackIdentityManager.end()(row 22) posted to/api/v1/auth/logout. A 1.0 server answers every v1 path except health with410, so sign-in would fail and sign-out would never revoke the server session.The v1 login answer carried an integer
user.idthat the app ignored.installSessionwrote an unverified binding (accountID: nil), soTokenStore.captureDurableAccountAuth()returned nil after every fresh sign-in until something else bound the account.Solution
AuthService.logincallsAPIv2Client.login(POST /api/v2/auth/login,non_retryable, public). The request goes out once with no bearer, and a 401 does not start a refresh.installSessiongains anaccountIDparameter, and login passesTokenPair.user.id, so the session is bound to a verified account. The QR sign-in passesniluntil W5-B moves it.APIv2Client.loginnow checks for200before it decodes the body.LoginViewModel.message(for:)maps v2 problem statuses to form copy: 401 wrong credentials, 403 account can't sign in, 400/422 check the fields, 429 too many attempts. Silo's login rejects only with problem documents, so a bare 401 or 403 (for example from an authenticating proxy or WAF) shows the generic "The server returned HTTP N." text instead of blaming the credentials or the account. A bare 429 still reads as too many attempts, because rate limiters may answer without a problem body. AnUpdateRequirementtakes precedence: a v1-only server shows the existing "server needs to be updated" copy, and a410 client_upgrade_requiredshows "Update Silo". Other errors keep their description.revokeSessionchanges only its path, to/api/v2/auth/logout. It still runs after local credentials are cleared, uses the captured bearer on its own URLSession with a 5 s timeout, never refreshes, and sends no profile headers.RemotePlaybackIdentityManager.end()callsSiloAPI.shared.apiV2Client.logout(expectedAccount:)while the temporary scope is still active. v2 logout does not acceptX-Profile-Id, soHTTPClient.requestDatagainssendsProfile(defaulttrue). Withfalse, it removesX-Profile-IdandX-Profile-Tokenafter the auth headers are attached, and again on the resend after a 401 refresh. Logout isnatural_idempotent, so that one resend is safe.APIv2Client.logoutstill requires204, and the caller still ignores failures (try?).LoginResponsemodel.LoginRequeststays as the v2LoginInputBody(a nilprovideris omitted).AuthUserstays because the v1 QR poll still uses it until W5-B.Failure outcomes
login(non_retryable)200with complete tokens: install the session bound touser.idand clear the old profile204: nothing more to donatural_idempotent)204, then the temporary scope endsValidation
AuthDeviceV2Tests,AccountSessionPersistenceTests,SettingValuesAPITests,UpdateRequirementTests,RefreshSessionV2Tests,RemotePlaybackRoutingTests,APIv2ContractStateTests,RestoredSessionValidatorTestsandCredentialIdentityTestspassed: 181 tests, 0 failures. The same nine classes underSiloTVTestspassed: 171 tests, 0 failures.scripts/ci/check-no-api-v1.shpassed. Noauth/loginorauth/logoutv1 literal remains in the app or tests. The owner-fence count iniosApp/iosAppstays at 60 lines./api/v2/auth/loginand bindscaptureDurableAccountAuth().accountIDto the returneduser.id./api/v2/auth/logoutwith the bearer and noX-Profile-Id/X-Profile-Token.APIv2Client.logoutsends only the bearer, both for a persistent session with a profile proof and for a SiloRemote temporary scope. The resend after a refresh also omits the profile header.APIv2Client.logoutrequires204, and a v1-only verdict sends nothing.sendsProfile: trueinAPIv2Client.logout,testLogoutSendsOnlyTheBearerfails on the leakedremote-proofheader.Risks and follow-ups
detail.AuthServiceto test, so this PR leaves it out.sendsProfileapplies only to account-scopedrequestDatacalls; scoped calls with arequestIdentityalways name a profile. The server contract does not state theX-Profile-Idrefusal as an explicit gate. This PR follows the plan and inventory (I15) and never sends the header on logout.AuthService.swift. The plan asks for it to land first if possible. Whichever lands second needs a rebase; theinstallSessionsignature change is the likely conflict.user.idintoinstallSession.AuthUserandImpersonationInfocan go once pairing (W5-C) moves too.AI disclosure
Code and description written by Claude Opus 5.5 (
claude-opus-5-5) agents in Claude Code (T3 Code), orchestrated by a Claude Code workflow.Part 11 of 50 in the Apple API v2 stack. Base:
apiv2-stack/10-validate-servers-through-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.🤖 Generated with Claude Code