Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/platform/auth/sso/SsoRequiredDialogContent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ 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: '<div />' } },
{ path: '/oauth/consent', component: { template: '<div />' } },
{
path: '/cloud/login',
name: 'cloud-login',
component: { template: '<div />' }
}
]
})
await router.push('/workflows?id=7')
await router.push(at)
return render(SsoRequiredDialogContent, {
props,
global: {
Expand Down Expand Up @@ -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<User>({ email: 'ada@acme.com' })
vi.mocked(useAuthStore().logout)
Expand Down
3 changes: 2 additions & 1 deletion src/platform/auth/sso/SsoRequiredDialogContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions src/platform/auth/sso/ssoReturnPath.ts
Original file line number Diff line number Diff line change
@@ -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}`
}
10 changes: 7 additions & 3 deletions src/platform/cloud/onboarding/CloudLoginView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ async function renderLoginView(
path: '/oauth/consent',
name: 'cloud-oauth-consent',
component: { template: '<div />' }
},
{
path: '/cloud/oauth/consent',
redirect: (to) => ({ path: '/oauth/consent', query: to.query })
}
]
})
Expand Down Expand Up @@ -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}`
)
})

Expand All @@ -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}`
)
})

Expand Down Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions src/platform/cloud/onboarding/composables/useSsoSignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion src/platform/cloud/onboarding/onboardingCloudRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
},
Expand Down
Loading