Skip to content

Commit 4f5d57b

Browse files
committed
improvement(oauth): remove unused scope hints (#2551)
* improvement(oauth): remove unused scope hints * improvement(oauth): remove scopeHints and extraneous oauth provider data * cleanup
1 parent 8090988 commit 4f5d57b

File tree

23 files changed

+1452
-761
lines changed

23 files changed

+1452
-761
lines changed

apps/sim/app/api/auth/oauth/connections/route.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('OAuth Connections API Route', () => {
7070
})
7171
)
7272

73-
vi.doMock('@/lib/oauth/oauth', () => ({
73+
vi.doMock('@/lib/oauth/utils', () => ({
7474
parseProvider: mockParseProvider,
7575
evaluateScopeCoverage: mockEvaluateScopeCoverage,
7676
}))

apps/sim/app/api/auth/oauth/connections/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { type NextRequest, NextResponse } from 'next/server'
55
import { getSession } from '@/lib/auth'
66
import { generateRequestId } from '@/lib/core/utils/request'
77
import { createLogger } from '@/lib/logs/console/logger'
8-
import type { OAuthProvider } from '@/lib/oauth/oauth'
9-
import { evaluateScopeCoverage, parseProvider } from '@/lib/oauth/oauth'
8+
import type { OAuthProvider } from '@/lib/oauth'
9+
import { evaluateScopeCoverage, parseProvider } from '@/lib/oauth'
1010

1111
const logger = createLogger('OAuthConnectionsAPI')
1212

apps/sim/app/api/auth/oauth/credentials/route.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('OAuth Credentials API Route', () => {
4242
getSession: mockGetSession,
4343
}))
4444

45-
vi.doMock('@/lib/oauth/oauth', () => ({
45+
vi.doMock('@/lib/oauth/utils', () => ({
4646
parseProvider: mockParseProvider,
4747
evaluateScopeCoverage: mockEvaluateScopeCoverage,
4848
}))

apps/sim/app/api/auth/oauth/credentials/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { z } from 'zod'
77
import { checkHybridAuth } from '@/lib/auth/hybrid'
88
import { generateRequestId } from '@/lib/core/utils/request'
99
import { createLogger } from '@/lib/logs/console/logger'
10-
import { evaluateScopeCoverage, parseProvider } from '@/lib/oauth/oauth'
10+
import { evaluateScopeCoverage, type OAuthProvider, parseProvider } from '@/lib/oauth'
1111
import { getUserEntityPermissions } from '@/lib/workspaces/permissions/utils'
1212

1313
export const dynamic = 'force-dynamic'
@@ -132,7 +132,7 @@ export async function GET(request: NextRequest) {
132132
}
133133

134134
// Parse the provider to get base provider and feature type (if provider is present)
135-
const { baseProvider } = parseProvider(providerParam || 'google-default')
135+
const { baseProvider } = parseProvider((providerParam || 'google') as OAuthProvider)
136136

137137
let accountsData
138138

apps/sim/app/api/auth/oauth/utils.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ vi.mock('@sim/db', () => ({
2626

2727
vi.mock('@/lib/oauth/oauth', () => ({
2828
refreshOAuthToken: vi.fn(),
29+
OAUTH_PROVIDERS: {},
2930
}))
3031

3132
vi.mock('@/lib/logs/console/logger', () => ({
@@ -38,7 +39,7 @@ vi.mock('@/lib/logs/console/logger', () => ({
3839
}))
3940

4041
import { db } from '@sim/db'
41-
import { refreshOAuthToken } from '@/lib/oauth/oauth'
42+
import { refreshOAuthToken } from '@/lib/oauth'
4243
import {
4344
getCredential,
4445
getUserId,

apps/sim/app/api/auth/oauth/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { account, workflow } from '@sim/db/schema'
33
import { and, desc, eq } from 'drizzle-orm'
44
import { getSession } from '@/lib/auth'
55
import { createLogger } from '@/lib/logs/console/logger'
6-
import { refreshOAuthToken } from '@/lib/oauth/oauth'
6+
import { refreshOAuthToken } from '@/lib/oauth'
77

88
const logger = createLogger('OAuthUtilsAPI')
99

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/credential-selector/components/oauth-required-modal.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { client } from '@/lib/auth/auth-client'
77
import { createLogger } from '@/lib/logs/console/logger'
88
import {
99
getProviderIdFromServiceId,
10-
getServiceIdFromScopes,
1110
OAUTH_PROVIDERS,
1211
type OAuthProvider,
1312
parseProvider,
@@ -21,7 +20,7 @@ export interface OAuthRequiredModalProps {
2120
provider: OAuthProvider
2221
toolName: string
2322
requiredScopes?: string[]
24-
serviceId?: string
23+
serviceId: string
2524
newScopes?: string[]
2625
}
2726

@@ -301,16 +300,15 @@ export function OAuthRequiredModal({
301300
serviceId,
302301
newScopes = [],
303302
}: OAuthRequiredModalProps) {
304-
const effectiveServiceId = serviceId || getServiceIdFromScopes(provider, requiredScopes)
305303
const { baseProvider } = parseProvider(provider)
306304
const baseProviderConfig = OAUTH_PROVIDERS[baseProvider]
307305

308306
let providerName = baseProviderConfig?.name || provider
309307
let ProviderIcon = baseProviderConfig?.icon || (() => null)
310308

311309
if (baseProviderConfig) {
312-
for (const service of Object.values(baseProviderConfig.services)) {
313-
if (service.id === effectiveServiceId || service.providerId === provider) {
310+
for (const [key, service] of Object.entries(baseProviderConfig.services)) {
311+
if (key === serviceId || service.providerId === provider) {
314312
providerName = service.name
315313
ProviderIcon = service.icon
316314
break
@@ -343,7 +341,7 @@ export function OAuthRequiredModal({
343341

344342
const handleConnectDirectly = async () => {
345343
try {
346-
const providerId = getProviderIdFromServiceId(effectiveServiceId)
344+
const providerId = getProviderIdFromServiceId(serviceId)
347345

348346
onClose()
349347

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/slack-selector/slack-selector-input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { useEffect, useMemo, useState } from 'react'
44
import { useParams } from 'next/navigation'
55
import { Tooltip } from '@/components/emcn'
6-
import { getProviderIdFromServiceId } from '@/lib/oauth/oauth'
6+
import { getProviderIdFromServiceId } from '@/lib/oauth'
77
import { SelectorCombobox } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/selector-combobox/selector-combobox'
88
import { useDependsOnGate } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-depends-on-gate'
99
import { useForeignCredential } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-foreign-credential'

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/components/tool-credential-selector.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Button, Combobox } from '@/components/emcn/components'
44
import {
55
getCanonicalScopesForProvider,
66
getProviderIdFromServiceId,
7-
getServiceIdFromScopes,
87
OAUTH_PROVIDERS,
98
type OAuthProvider,
109
type OAuthService,
@@ -45,7 +44,7 @@ interface ToolCredentialSelectorProps {
4544
provider: OAuthProvider
4645
requiredScopes?: string[]
4746
label?: string
48-
serviceId?: OAuthService
47+
serviceId: OAuthService
4948
disabled?: boolean
5049
}
5150

@@ -65,15 +64,7 @@ export function ToolCredentialSelector({
6564

6665
const selectedId = value || ''
6766

68-
const effectiveServiceId = useMemo(
69-
() => serviceId || getServiceIdFromScopes(provider, requiredScopes),
70-
[provider, requiredScopes, serviceId]
71-
)
72-
73-
const effectiveProviderId = useMemo(
74-
() => getProviderIdFromServiceId(effectiveServiceId),
75-
[effectiveServiceId]
76-
)
67+
const effectiveProviderId = useMemo(() => getProviderIdFromServiceId(serviceId), [serviceId])
7768

7869
const {
7970
data: credentials = [],
@@ -240,7 +231,7 @@ export function ToolCredentialSelector({
240231
toolName={getProviderName(provider)}
241232
requiredScopes={getCanonicalScopesForProvider(effectiveProviderId)}
242233
newScopes={missingRequiredScopes}
243-
serviceId={effectiveServiceId}
234+
serviceId={serviceId}
244235
/>
245236
)}
246237
</>

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
getProviderIdFromServiceId,
2525
type OAuthProvider,
2626
type OAuthService,
27-
} from '@/lib/oauth/oauth'
27+
} from '@/lib/oauth'
2828
import {
2929
CheckboxList,
3030
Code,

0 commit comments

Comments
 (0)