mirror of
https://github.com/Comfy-Org/comfy-swift-sdk.git
synced 2026-11-04 23:47:26 +00:00
[PR #33] [MERGED] feat(auth): ComfyWebAuthPresenter + one-call ComfyAuth.signIn #35
Labels
No labels
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-swift-sdk#35
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Comfy-Org/comfy-swift-sdk/pull/33
Author: @mattmillerai
Created: 7/7/2026
Status: ✅ Merged
Merged: 7/7/2026
Merged by: @mattmillerai
Base:
main← Head:matt/be-2451-signin-orchestrator📝 Commits (3)
f744342feat(auth): add ComfyWebAuthPresenter + ComfyAuth.signIn one-call orchestrator (BE-2451)9fbf3bafix(auth): address Cursor review — session lifetime, main-actor presenter, empty-token guard0b35e38docs(auth): harden the WebAuthPresenter sample against a start() hang📊 Changes
5 files changed (+588 additions, -4 deletions)
View changed files
📝
README.md(+66 -4)➕
Sources/ComfySwiftSDK/Public/ComfyAuthSignIn.swift(+96 -0)📝
Sources/ComfySwiftSDK/Public/ComfyCloudClient.swift(+7 -0)➕
Sources/ComfySwiftSDK/Public/ComfyWebAuthPresenter.swift(+46 -0)➕
Tests/ComfySwiftSDKTests/ComfyAuthSignInTests.swift(+373 -0)📄 Description
ELI-5
Signing into Comfy Cloud is a little dance: open a browser to log in, catch the redirect, swap the code for tokens, save them, and hand back a ready client. Every app was choreographing that dance by hand. This PR turns it into one call —
ComfyAuth.signIn(presenter:store:)— while keeping the one step the SDK can't own (popping the browser) app-side through a tiny protocol, so the SDK still never importsAuthenticationServices.What & why
Adds the one-call interactive sign-in that composes the primitives from the two preceding auth PRs (config + authorize/exchange, and the token-store/restore-client) into the full flow, mirroring Comfy-iOS's
OAuthCoordinator.signIn()with the browser step lifted out behind an injected protocol.New public surface (Foundation-only, DocC'd):
ComfyWebAuthPresenter— aSendableprotocol withauthenticate(url:callbackURLScheme:) async throws -> URL. An app conforms a thin adapter over itsASWebAuthenticationSession; conformers throwComfyError.authCancelledon user dismissal. This is the seam that keepsAuthenticationServicesout of the SDK's import boundary.ComfyAuth.signIn(presenter:store:config:)— build → present → verifystate+ extract code → exchange → persist → return a ready.oauthRefreshableclient. The security-critical callback validation (extractCode(fromCallback:), which enforces thestatematch) is done by the SDK, never the presenter..authCancelled,.authStateMismatch, and exchangeComfyErrors propagate unchanged.Internal:
makeRefreshableCredential(the exact pathrestoreClientuses), seeding the expiry cache from the just-persistedexpiresAt— no redundant store re-load, and norestoreClient(...)!force-unwrap (which would crash on a degenerate empty-token response; the direct build instead degrades to.authInvalidon first use).ComfyCloudClient.credentialis exposed internally (not public) so tests can assert the returned client's credential mode.Testing
swift buildclean and the fullswift testsuite green (212 tests), includingImportBoundaryTests(Foundation-only enforced). NewComfyAuthSignInTestsuses a fakeComfyWebAuthPresenter(valid / cancelled / missing-code / tampered-state) + an in-memoryComfyTokenStore, over an injected exchange seam (the real staticexchangeAuthorizationCodebuilds its ownURLSession, so it isn't interceptable by the test URL protocol). Asserts: refreshable client returned, tokens persisted, code+verifier+config threaded into the exchange, and every error branch propagates without touching the store.Notes / judgment calls
matt/be-2450-token-store-restore-client(#32), which itself stacks on #31. Review shows only this PR's net diff; GitHub retargets tomainas the foundations merge.store.savefailures propagate as their raw error (not remapped to.unknown). The spec calls for unchanged propagation of.authCancelled/.authStateMismatch/ exchange errors only; surfacing a native persistence error (e.g. a Keychain write failure) at interactive sign-in time — where the caller has full context — read as the better behavior than obscuring it. Easy to change if a reviewer prefers the.unknownwrap that the ongoing-refresh closure uses.signInpath contains zero log calls, andComfyStoredTokensalready redacts itsdescription/debugDescription(covered by the existingLoggingPrivacysuite).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.