Skip to content

Commit 102e5b4

Browse files
committed
fix(quickbooks): route credential OAuth through drafts
1 parent 8b868be commit 102e5b4

3 files changed

Lines changed: 50 additions & 11 deletions

File tree

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { useSession } from '@/lib/auth/auth-client'
4646
import type { OAuthConnectEventDetail } from '@/lib/copilot/tools/client/base-tool'
4747
import { consumeOAuthReturnContext, writeOAuthReturnContext } from '@/lib/credentials/client-state'
4848
import type { OAuthProvider } from '@/lib/oauth'
49+
import { usesCredentialConfiguredOAuthClient } from '@/lib/oauth/utils'
4950
import { OPERATION_SUBBLOCK_ID } from '@/lib/permission-groups/operation-access'
5051
import {
5152
DEFAULT_HORIZONTAL_SPACING,
@@ -343,6 +344,9 @@ const WorkflowContent = React.memo(
343344
requiredScopes: string[]
344345
newScopes?: string[]
345346
} | null>(null)
347+
const oauthModalRequiresDraft = oauthModal
348+
? usesCredentialConfiguredOAuthClient(oauthModal.provider)
349+
: false
346350

347351
const params = useParams()
348352
const router = useRouter()
@@ -589,16 +593,18 @@ const WorkflowContent = React.memo(
589593
const detail = (event as CustomEvent<OAuthConnectEventDetail>).detail
590594
if (!detail) return
591595

592-
writeOAuthReturnContext({
593-
origin: 'workflow',
594-
workflowId: workflowIdParam,
595-
displayName: detail.providerName,
596-
providerId: detail.providerId,
597-
preCount: 0,
598-
workspaceId,
599-
reconnect: true,
600-
requestedAt: Date.now(),
601-
})
596+
if (!usesCredentialConfiguredOAuthClient(detail.providerId)) {
597+
writeOAuthReturnContext({
598+
origin: 'workflow',
599+
workflowId: workflowIdParam,
600+
displayName: detail.providerName,
601+
providerId: detail.providerId,
602+
preCount: 0,
603+
workspaceId,
604+
reconnect: true,
605+
requestedAt: Date.now(),
606+
})
607+
}
602608

603609
setOauthModal({
604610
provider: detail.providerId as OAuthProvider,
@@ -5342,7 +5348,27 @@ const WorkflowContent = React.memo(
53425348

53435349
{!embedded && <Panel />}
53445350

5345-
{!embedded && oauthModal && (
5351+
{!embedded && oauthModal && oauthModalRequiresDraft && (
5352+
<ConnectOAuthModal
5353+
mode='connect'
5354+
origin='workflow'
5355+
open={true}
5356+
onOpenChange={(open) => {
5357+
if (!open) {
5358+
consumeOAuthReturnContext()
5359+
setOauthModal(null)
5360+
}
5361+
}}
5362+
provider={oauthModal.provider}
5363+
providerId={oauthModal.provider}
5364+
serviceId={oauthModal.serviceId}
5365+
requiredScopes={oauthModal.requiredScopes}
5366+
workspaceId={workspaceId}
5367+
workflowId={workflowIdParam}
5368+
/>
5369+
)}
5370+
5371+
{!embedded && oauthModal && !oauthModalRequiresDraft && (
53465372
<ConnectOAuthModal
53475373
mode='reauthorize'
53485374
open={true}

apps/sim/lib/oauth/utils.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
getServiceConfigByServiceId,
1616
parseProvider,
1717
providerIdsForService,
18+
usesCredentialConfiguredOAuthClient,
1819
} from './utils'
1920

2021
describe('getAllOAuthServices', () => {
@@ -180,6 +181,14 @@ describe('getServiceByProviderAndId', () => {
180181
})
181182
})
182183

184+
describe('usesCredentialConfiguredOAuthClient', () => {
185+
it.concurrent('distinguishes user-supplied OAuth apps from deployment OAuth clients', () => {
186+
expect(usesCredentialConfiguredOAuthClient('quickbooks')).toBe(true)
187+
expect(usesCredentialConfiguredOAuthClient('slack')).toBe(false)
188+
expect(usesCredentialConfiguredOAuthClient('unknown-provider')).toBe(false)
189+
})
190+
})
191+
183192
describe('getProviderIdFromServiceId', () => {
184193
it.concurrent('should return correct providerId for Gmail', () => {
185194
const providerId = getProviderIdFromServiceId('gmail')

apps/sim/lib/oauth/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,10 @@ export function getServiceConfigByProviderId(providerId: string): OAuthServiceCo
626626
return null
627627
}
628628

629+
export function usesCredentialConfiguredOAuthClient(providerId: string): boolean {
630+
return Boolean(getServiceConfigByProviderId(providerId)?.clientConfiguration)
631+
}
632+
629633
export function getServiceAccountProviderForProviderId(providerId: string): string | undefined {
630634
const serviceConfig = getServiceConfigByProviderId(providerId)
631635
return serviceConfig?.serviceAccountProviderId

0 commit comments

Comments
 (0)