Repository navigation
feat(auth): use shared account sessions for Desktop login - #1775
PabloWiedemann wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
🔍 Cursor Review — Consolidated panel
Triggered by @PabloWiedemann.
Found 10 finding(s).
| Severity | Count |
|---|---|
| 🟠 High | 5 |
| 🟡 Medium | 5 |
Panel: 8/8 reviewers contributed findings.
There was a problem hiding this comment.
🔍 Cursor Review — Consolidated panel
Triggered by @PabloWiedemann.
Found 10 finding(s).
| Severity | Count |
|---|---|
| 🟠 High | 2 |
| 🟡 Medium | 5 |
| 🟢 Low | 3 |
Panel: 7/8 reviewers contributed findings.
Reviewers that did not contribute: gpt-5.6-sol-max:edge-case (empty)
benceruleanlu
left a comment
There was a problem hiding this comment.
This review was performed agentically. Ben will be notified to review manually soon.
Recommendation: fix the 1 blocking finding below before merging.
Review details
The PR moves Desktop sign-in to a shared account session. Desktop requests a dls_ login code, polls until the hosted login completes, then gets workspace tokens from /auth/token using the stored comfy-session- credential. Workspace switches and refreshes now get new tokens from the server instead of asking for OAuth consent per workspace. It also adds a getPartnerNodeToken method for the local ComfyUI bridge, and logout now revokes the session on the server.
Blocking
-
src/main/cloud/accountSession.ts:31(called fromsrc/main/cloud/session.ts:240): sign-in has no fallback anymore.authenticateAtGenerationused to calloauth.signIn. Now it always callssignInAccount, andsignInAccountthrows'Account login is unavailable on this server'whenever the server returns a code without thedls_prefix.oauth.signInis still exported but nothing calls it. So sign-in fails completely, for every user, against any backend that doesn't honorsession_type: 'account'. That includes:- a backend deployed before the companion PRs;
- any user left out of the shared-session rollout, which the PR body says is still gated ("include non-SSO Desktop users in the existing shared-session rollout");
- any other environment
CLOUD_CONFIG.issuerpoints at.
Existing OAuth users keep refreshing, but anyone who signs out, or whose refresh fails, can't sign back in. Your own description depends on deploy order and rollout settings to avoid this.
Smallest fix: when the code isn't
dls_, fall back to the legacysignIn({ onAuthorizeUrl })flow instead of throwing. Alternatively, have the server error explicitly, and fall back only on that error.
Optional
-
src/main/lib/ipc/registerDevPlatformHandlers.ts:184-187:signOutOfCloudnow waits for the server revocation and passes its errors back to the caller. When offline, or when/auth/token/revokefails, local credentials are already gone andSIGNED_OUThas already been broadcast, but the IPC call still rejects:- The embedded
desktop2-auth:sign-outhandler throws to the hosted frontend, even though the user is actually signed out. DevPlatformAccountChip.vue:37takes itscatch { return }path and never emitssigned-out.
The session token was cleared before the request, so nothing can retry the revocation anyway. Logging the error and resolving
SIGNED_OUTwould match what actually happened.Also, in
revokeAccountSession(accountSession.ts:187-192), thetry/finallyre-throws an error from/auth/token/revokeeven when theDELETE /auth/sessioncall succeeded. - The embedded
-
src/main/cloud/session.ts:326: on a 401,onUnauthorizednow callsinvalidateStoredSession(). That clears the session token locally but never revokes it on the server, unlikelogout(). The account session stays valid on the server until it expires. This is low cost, but the call already sits on lines this PR changes.
Review target
- Head tip:
0fbc0d3f73130b532ff245a1f192eefd2a4cb577 maintip:195ae80ae06ac5cf9e9c3b2978ea5e0b73f1f464
benceruleanlu
left a comment
There was a problem hiding this comment.
Coderabbit tagged me, do you need me? Assign if so @PabloWiedemann
|
Consolidated review follow-up in
Validation: 129 focused tests and required typecheck/lint/format hooks passed. New-head CI is running. |
dante01yoon
left a comment
There was a problem hiding this comment.
Thanks for the thorough follow-ups on the Cursor findings. I left one blocking issue and a few smaller points inline.
Gates
- Real problem: passes. Moving off per-workspace OAuth consent and supporting SSO-only accounts is a real need.
- Server owns session facts: mostly passes. Workspace membership and token scope come from
/auth/token, and partner tokens are re-checked against the requested workspace. One exception: server capability is inferred from thedls_code prefix (see the question onaccountSession.ts:31). - Generated API types: not applicable. This repo has no generated cloud API types;
desktopLoginCode/client.tsandcomfybuilder/types.tsalso hand-validate wire shapes, somintedTokensfollows the local convention.
Security notes (no action needed)
- The session credential stays in main and in the
safeStoragevault. - The new
desktop2-auth:get-partner-node-tokenchannel validates its input and checksisTrustedSenderboth before and after the await. - PKCE binds the exchange to the verifier, and requests use
credentials: 'omit'andredirect: 'error'. - Logout clears local state before revoking on the server.
Size
- About 390 non-test lines. Consider splitting the partner-node bridge (IPC channel, preload, bridge types, partner cache in
CloudSession) from the account-login change. Each half would be easier to review and roll back.
Unanchored
- nit-pick (non-blocking): the new exports (
signInAccount,mintWorkspaceToken,mintPartnerNodeToken,revokeAccountSession,partnerNodeTokenForSender) andgetPartnerNodeTokenin the published bridge types have no JSDoc, while their neighbours do. A one-line JSDoc would help, especially on the bridge type, which consumers read. - question:
cloud/index.tsstill exportssignInfrom./oauth, but nothing in the app calls it anymore. Is it intentionally kept as the fallback path, or can it be removed?
| loadTokens()?.sessionToken === tokens.sessionToken && | ||
| tokens.sessionToken | ||
| ) { | ||
| this.invalidateStoredSession() |
There was a problem hiding this comment.
issue: this clears the stored session but never tells the renderers, so the account chip can keep showing "signed in" after Desktop has signed out locally.
Scenario: the account session is revoked or expires on the server, and the workspace JWT then expires. On the next catalog call, ComfyBuilderClient.accessToken() calls getAccessToken(). That reaches doRefresh, which gets a 401 from /auth/token, clears the tokens here, and returns null. The client then throws 'Not signed in' before sending any request, so onUnauthorized (and therefore setUnauthorizedHandler's broadcastAuthChanged(SIGNED_OUT)) never runs.
Before this PR, a failed legacy refresh kept the tokens, so the next request's 401 went through onUnauthorized and the broadcast fired. switchCloudWorkspace broadcasts its own result, so only this refresh path is affected.
Could the refresh-401 invalidation go through the same signed-out notification? For example, pass a callback into CloudSession, or have asTokenProvider signal it. A test should assert that the broadcast happens. (CONFIRMED by reading the code path; not run.)
| }, | ||
| { signal } | ||
| ) | ||
| if (!grant.code.startsWith('dls_')) { |
There was a problem hiding this comment.
question: Ben's blocking point about this hard throw (no fallback to oauth.signIn when the server doesn't issue a dls_ code) hasn't had a reply yet. The test refuses an older server before opening a Firebase-only handoff suggests the throw is intentional.
Can you confirm the plan? That would mean the backend must deploy first, and every environment COMFY_CLOUD_ISSUER can point at (staging, mocks) must support session_type: 'account' before this ships.
Related: detecting server support from the code's prefix is a client-side guess. An explicit field in the grant (e.g. echoing session_type) would make the server's answer authoritative.
| await abortableSleep(grant.poll_interval * 1000, deadline) | ||
| let response | ||
| try { | ||
| response = await postJson( |
There was a problem hiding this comment.
suggestion: this loop re-implements the exchange that exchangeDesktopLoginCode and signInViaDesktopLoginCode already handle. In doing so it drops the POLL_JITTER_MS jitter, which the existing flow adds "so a fleet of desktops doesn't sync-poll".
Consider widening exchangeDesktopLoginCode to accept the session_token completion, then reusing it here along with the jittered sleep. That keeps a single exchange contract instead of two.
| this.invalidateStoredSession() | ||
| return this.status() | ||
| } | ||
| return this.status() |
There was a problem hiding this comment.
suggestion: returning the current status keeps the bridge contract, which makes sense after the earlier thread. But non-401 mint failures here (network errors, 403/404 non-member) and the wrong-workspace response at L213-214 now leave no trace: the picker click just does nothing.
A sanitized console.warn, like the one logout() emits, would make these cases debuggable. Also, L203-207 return this.status() in both branches, so the condition only gates invalidateStoredSession() and could be flattened.
Summary
Desktop sign-in now opens the existing hosted login and receives an independent shared account session, including for SSO-only accounts. Switching workspaces calls the existing backend token endpoint; it no longer requires a separate OAuth consent grant for each workspace.
The account credential remains in the main process and existing encrypted token store. The optional local ComfyUI bridge receives only its partner-node credential. Existing OAuth sessions can still refresh until the next sign-in. No new dependency, screen, or workspace permission model is introduced.
Blast radius: Desktop account login, token renewal, workspace selection, logout, and the trusted local partner-node bridge. Deploy the backend handoff and hosted redemption changes first; include non-SSO Desktop users in the existing shared-session rollout.
Supersedes closed #1749. Companions: backend transport, backend handoff, hosted redemption, Desktop.
Change breakdown
Changed lines means additions + deletions. Counts use the PR base; no merge-only changes are included.
Total: 17 files, 922 changed lines.
Paths by category
Generated code
packages/comfyui-desktop-bridge-types/comfyDesktopBridge.d.ts(+1/−0)Configuration
packages/comfyui-desktop-bridge-types/package.json(+1/−1)Product code
src/main/auth/desktopLoginCode/client.ts(+1/−0)src/main/cloud/accountSession.ts(+194/−0)src/main/cloud/session.ts(+161/−20)src/main/cloud/tokenStore.ts(+8/−3)src/main/cloud/types.ts(+2/−1)src/main/lib/embeddedSession.ts(+17/−1)src/main/lib/ipc/registerDevPlatformHandlers.ts(+2/−1)src/main/lib/ipc/registerEmbeddedSessionHandlers.ts(+5/−0)src/preload/comfyPreload.ts(+2/−0)src/types/comfyDesktopBridge.ts(+1/−0)Tests
src/main/cloud/accountSession.test.ts(+194/−0)src/main/cloud/session.test.ts(+200/−46)src/main/cloud/tokenStore.test.ts(+33/−0)src/main/lib/embeddedSession.test.ts(+22/−1)src/main/lib/ipc/registerEmbeddedSessionHandlers.test.ts(+3/−1)Verification
8c0a6acepassed, including OS E2E checks (rechecked October 22).