From 00004447727cd6747111feea5988a3742e82ec98 Mon Sep 17 00:00:00 2001 From: Dante Date: Wed, 7 Oct 2026 23:03:28 +0000 Subject: [PATCH] FE-3298 fix(cloud): return SSO to the consent path the server serves (#20468) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary An OAuth sign-in (Comfy Desktop, MCP clients) that goes through SSO lands on a JSON 404 instead of the consent page, so a first-time SSO user can never finish signing in. SSO now returns to `/cloud/oauth/consent`, the consent path the server serves as a page. - Fixes FE-3298 **Why:** a person with no Cloud session who picks Continue with SSO during an OAuth sign-in is stuck on `{"code":"NOT_FOUND"}`. This blocks the Oct 15 internal Desktop SSO test, since every first sign-in takes this path. With an existing Cloud session the SSO step is skipped, which is why it went unnoticed. **Root cause:** `resolveSsoReturnTo` (added in #20217) resolves the pending consent by route name, which gives `/oauth/consent`. That route only exists inside the SPA. The SSO callback is a full page load, and the server answers `/oauth/consent` with a 404 on testcloud and prod. Only `/cloud/oauth/consent` is served as a page; the SPA then redirects it to `/oauth/consent`. | Path | testcloud | prod | |---|---|---| | `/oauth/consent` | 404 JSON | 404 JSON | | `/cloud/oauth/consent` | 200 HTML | 200 HTML | **How:** one helper, `toSsoReturnPath`, maps `/oauth/consent` to `/cloud/oauth/consent` (query kept) for every SSO return: - `resolveSsoReturnTo`: the login/signup pages' Continue with SSO and the post-Firebase `sso_required` handoff. - `SsoRequiredDialogContent`: its fallback to the current route, so a refusal raised on the consent page itself (e.g. by the consent route's session setup or a re-mint) no longer returns to the 404. The legacy redirect route now notes that SSO depends on it, so it isn't removed before BE-4146 serves `/oauth/consent`. **Every OAuth sign-in path** (context from #14006 and #15026): | Path into consent | Navigation | Before | After | |---|---|---|---| | Signed in: `/oauth/authorize` → 302 `/cloud/oauth/consent` | full load, then SPA redirect | ok | ok (untouched) | | Signed out, Firebase sign-in on `/cloud/login?oauth_request_id=` | SPA `router.push` by name | ok | ok (untouched) | | Signed out, Continue with SSO on login or signup | SSO callback full load | **404** | ok | | Firebase sign-in refused with `sso_required` on the login page | SSO callback full load | **404** | ok | | SSO error, retry with the id kept in storage | SSO callback full load | **404** | ok | | `sso_required` dialog raised on the consent page | SSO callback full load | **404** | ok | | Legacy `/login` (#15026) | SPA redirect to `cloud-login`, query kept | ok | ok (untouched) | ## Plan position | PR | Scope | State | |---|---|---| | #20217 | `sso_enabled` flag, SSO sign-in (introduced the bug) | merged | | #20383 | Desktop local signs in with the Desktop session | in review | | **this PR** | **SSO returns to a served consent path** | **open** | | FE-3297 | Workspace switching under Desktop host auth | follow-up | ```mermaid flowchart LR A["#20217 SSO sign-in"] --> C["this PR: consent return fix"] B["#20383 Desktop host session"] --> D["Oct 15 internal test"] C --> D D --> E["FE-3297 workspace switch"] style C fill:#f5c518,color:#000 ``` ## Verification - **Unit tests:** `CloudLoginView.test.ts` pinned the broken `/oauth/consent` return in three cases. - With the old source, those three fail. - With this change, all 65 tests in `CloudLoginView.test.ts` and `onboardingCloudRoutes.test.ts` pass. - **E2E:** none added. The flow needs a real IdP and a server-side SSO callback, which the Playwright mocks don't cover; the unit test pins the `returnTo` value the server receives. - **Manual (before merge):** on the PR preview against testcloud, signed out: 1. Start a Desktop sign-in. 2. Pick Continue with SSO and sign in as `ssotest1@example.com`. 3. Confirm the consent page loads and Desktop finishes signing in. ### AS IS Signed out, Continue with SSO during a Desktop sign-in returns to `/oauth/consent`, which the server answers with a JSON 404. ### TO BE SSO returns to `/cloud/oauth/consent`; after the IdP the same flow reaches the consent page. Verified on testcloud Oct 7; the token exchange completed (`sign_in_provider: saml.workos`, `client_id: comfy-desktop`).
Steps
--- .../auth/sso/SsoRequiredDialogContent.test.ts | 32 +++++++++++++++---- .../auth/sso/SsoRequiredDialogContent.vue | 3 +- src/platform/auth/sso/ssoReturnPath.ts | 13 ++++++++ .../cloud/onboarding/CloudLoginView.test.ts | 10 ++++-- .../onboarding/composables/useSsoSignIn.ts | 12 ++++--- .../cloud/onboarding/onboardingCloudRoutes.ts | 3 +- 6 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 src/platform/auth/sso/ssoReturnPath.ts diff --git a/src/platform/auth/sso/SsoRequiredDialogContent.test.ts b/src/platform/auth/sso/SsoRequiredDialogContent.test.ts index 58578a93054..dc12dc13aca 100644 --- a/src/platform/auth/sso/SsoRequiredDialogContent.test.ts +++ b/src/platform/auth/sso/SsoRequiredDialogContent.test.ts @@ -12,15 +12,19 @@ import { useAuthStore } from '@/stores/authStore' vi.mock(import('firebase/auth')) -async function renderDialog(props: { - email?: string - returnTo?: string - organizationId?: string -}) { +async function renderDialog( + props: { + email?: string + returnTo?: string + organizationId?: string + }, + at = '/workflows?id=7' +) { const router = createRouter({ history: createMemoryHistory(), routes: [ { path: '/workflows', component: { template: '
' } }, + { path: '/oauth/consent', component: { template: '
' } }, { path: '/cloud/login', name: 'cloud-login', @@ -28,7 +32,7 @@ async function renderDialog(props: { } ] }) - await router.push('/workflows?id=7') + await router.push(at) return render(SsoRequiredDialogContent, { props, global: { @@ -102,6 +106,22 @@ describe('SsoRequiredDialogContent', () => { ) }) + it('returns from the consent page to the consent path the server serves', async () => { + await renderDialog( + { email: 'ada@acme.com' }, + '/oauth/consent?oauth_request_id=req-1' + ) + + await userEvent.click( + screen.getByRole('button', { name: 'auth.sso.continueWithSso' }) + ) + + await waitFor(() => expect(assign).toHaveBeenCalledOnce()) + expect(assigned(assign).searchParams.get('return_to')).toBe( + '/cloud/oauth/consent?oauth_request_id=req-1' + ) + }) + it('lets the person retry when signing the account out fails', async () => { useAuthStore().currentUser = fromPartial({ email: 'ada@acme.com' }) vi.mocked(useAuthStore().logout) diff --git a/src/platform/auth/sso/SsoRequiredDialogContent.vue b/src/platform/auth/sso/SsoRequiredDialogContent.vue index 783bf782ee4..670d0d2e265 100644 --- a/src/platform/auth/sso/SsoRequiredDialogContent.vue +++ b/src/platform/auth/sso/SsoRequiredDialogContent.vue @@ -51,6 +51,7 @@ import { ssoStartUrl } from '@comfyorg/account-core/sso' import Button from '@/components/ui/button/Button.vue' import { useErrorHandling } from '@/composables/useErrorHandling' import { SSO_REQUIRED_DIALOG_KEY } from '@/platform/auth/sso/ssoRequiredDialogKey' +import { toSsoReturnPath } from '@/platform/auth/sso/ssoReturnPath' import { SSO_ENTRY_OPEN_QUERY } from '@/platform/cloud/onboarding/sso/ssoEntryQuery' import { useAuthStore } from '@/stores/authStore' import { useDialogStore } from '@/stores/dialogStore' @@ -75,7 +76,7 @@ function dismiss() { function destination(): string { const back = { - returnTo: returnTo ?? router.currentRoute.value.fullPath, + returnTo: toSsoReturnPath(returnTo ?? router.currentRoute.value.fullPath), origin: window.location.origin } if (organizationId) { diff --git a/src/platform/auth/sso/ssoReturnPath.ts b/src/platform/auth/sso/ssoReturnPath.ts new file mode 100644 index 00000000000..e7435af334a --- /dev/null +++ b/src/platform/auth/sso/ssoReturnPath.ts @@ -0,0 +1,13 @@ +const SPA_ONLY_CONSENT_PATH = '/oauth/consent' +const SERVED_CONSENT_PATH = '/cloud/oauth/consent' + +/** + * The path SSO's callback can land on with a full page load. The server + * serves the consent page only at `/cloud/oauth/consent`, which the SPA then + * redirects; a direct `/oauth/consent` load gets a 404. + */ +export function toSsoReturnPath(fullPath: string): string { + const url = new URL(fullPath, 'http://sso.invalid') + if (url.pathname !== SPA_ONLY_CONSENT_PATH) return fullPath + return `${SERVED_CONSENT_PATH}${url.search}${url.hash}` +} diff --git a/src/platform/cloud/onboarding/CloudLoginView.test.ts b/src/platform/cloud/onboarding/CloudLoginView.test.ts index 425ceccb1dd..0ef4f797d18 100644 --- a/src/platform/cloud/onboarding/CloudLoginView.test.ts +++ b/src/platform/cloud/onboarding/CloudLoginView.test.ts @@ -93,6 +93,10 @@ async function renderLoginView( path: '/oauth/consent', name: 'cloud-oauth-consent', component: { template: '
' } + }, + { + path: '/cloud/oauth/consent', + redirect: (to) => ({ path: '/oauth/consent', query: to.query }) } ] }) @@ -361,7 +365,7 @@ describe('CloudLoginView SSO', () => { await waitFor(() => expect(assign).toHaveBeenCalledOnce()) expect(startParams(assign).returnTo).toBe( - `/oauth/consent?oauth_request_id=${OAUTH_REQUEST_ID}` + `/cloud/oauth/consent?oauth_request_id=${OAUTH_REQUEST_ID}` ) }) @@ -374,7 +378,7 @@ describe('CloudLoginView SSO', () => { await waitFor(() => expect(assign).toHaveBeenCalledOnce()) expect(startParams(assign).returnTo).toBe( - `/oauth/consent?oauth_request_id=${OAUTH_REQUEST_ID}` + `/cloud/oauth/consent?oauth_request_id=${OAUTH_REQUEST_ID}` ) }) @@ -577,7 +581,7 @@ describe('CloudLoginView Firebase sign-in refused for SSO', () => { { name: 'returns SSO to a pending OAuth consent before the previous page', url: `/cloud/login?previousFullPath=%2Fworkflows&oauth_request_id=${OAUTH_REQUEST_ID}`, - returnTo: `/oauth/consent?oauth_request_id=${OAUTH_REQUEST_ID}` + returnTo: `/cloud/oauth/consent?oauth_request_id=${OAUTH_REQUEST_ID}` } ])('with the flag on, $name', async ({ url, returnTo }) => { const flags = vi.mocked(useFeatureFlags().flags) diff --git a/src/platform/cloud/onboarding/composables/useSsoSignIn.ts b/src/platform/cloud/onboarding/composables/useSsoSignIn.ts index 1a9c861d94b..7dd53203350 100644 --- a/src/platform/cloud/onboarding/composables/useSsoSignIn.ts +++ b/src/platform/cloud/onboarding/composables/useSsoSignIn.ts @@ -5,6 +5,8 @@ import { useRoute, useRouter } from 'vue-router' import { discoverSso, ssoStartUrl } from '@comfyorg/account-core/sso' +import { toSsoReturnPath } from '@/platform/auth/sso/ssoReturnPath' + import { captureOAuthRequestId, getOAuthRequestId @@ -34,10 +36,12 @@ export function resolveSsoReturnTo( const oauthRequestId = captureOAuthRequestId(route.query) ?? getOAuthRequestId() if (oauthRequestId) { - return router.resolve({ - name: 'cloud-oauth-consent', - query: { oauth_request_id: oauthRequestId } - }).href + return toSsoReturnPath( + router.resolve({ + name: 'cloud-oauth-consent', + query: { oauth_request_id: oauthRequestId } + }).href + ) } return getSafePreviousFullPath(route.query) ?? SSO_DEFAULT_RETURN_TO } diff --git a/src/platform/cloud/onboarding/onboardingCloudRoutes.ts b/src/platform/cloud/onboarding/onboardingCloudRoutes.ts index 1930314ac1c..57dbc2bfab8 100644 --- a/src/platform/cloud/onboarding/onboardingCloudRoutes.ts +++ b/src/platform/cloud/onboarding/onboardingCloudRoutes.ts @@ -152,7 +152,8 @@ export const cloudOnboardingRoutes: RouteRecordRaw[] = [ // the old consent path with `?oauth_request_id=...`; the route moved to // `/oauth/consent`. Redirect the old path (query preserved) so the browser // authorize flow works before the backend `frontendConsentPath` is updated. - // Remove once BE-4146 lands the backend path change. + // SSO's returnTo lands here too, since the server only serves this path as + // a page. Remove once BE-4146 serves `/oauth/consent`. path: '/cloud/oauth/consent', redirect: (to) => ({ path: '/oauth/consent', query: to.query }) },