Skip to content

Commit b093550

Browse files
authored
fix(credentials): remove special scopes from additional scopes required hook, remove additionalScopes arg from tool definition (#1905)
1 parent 9b702c4 commit b093550

File tree

137 files changed

+52
-226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+52
-226
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ import {
2121
import { Switch } from '@/components/ui/switch'
2222
import { Toggle } from '@/components/ui/toggle'
2323
import { createLogger } from '@/lib/logs/console/logger'
24-
import type { OAuthProvider, OAuthService } from '@/lib/oauth/oauth'
24+
import {
25+
getCanonicalScopesForProvider,
26+
type OAuthProvider,
27+
type OAuthService,
28+
} from '@/lib/oauth/oauth'
2529
import { cn } from '@/lib/utils'
2630
import {
2731
ChannelSelectorInput,
@@ -1713,7 +1717,7 @@ export function ToolInput({
17131717
value={tool.params.credential || ''}
17141718
onChange={(value) => handleParamChange(toolIndex, 'credential', value)}
17151719
provider={oauthConfig.provider as OAuthProvider}
1716-
requiredScopes={oauthConfig.additionalScopes || []}
1720+
requiredScopes={getCanonicalScopesForProvider(oauthConfig.provider)}
17171721
label={`Select ${oauthConfig.provider} account`}
17181722
serviceId={oauthConfig.provider}
17191723
disabled={disabled}

apps/sim/hooks/use-oauth-scope-status.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,40 @@ export function getCredentialsNeedingReauth(credentials: Credential[]): Credenti
4444
return credentials.filter(credentialNeedsReauth)
4545
}
4646

47+
/**
48+
* Scopes that control token behavior but are not returned in OAuth token responses.
49+
* These should be ignored when validating credential scopes.
50+
*/
51+
const IGNORED_SCOPES = new Set([
52+
'offline_access', // Microsoft - requests refresh token
53+
'refresh_token', // Salesforce - requests refresh token
54+
'offline.access', // Airtable - requests refresh token (note: dot not underscore)
55+
])
56+
4757
/**
4858
* Compute which of the provided requiredScopes are NOT granted by the credential.
59+
* Note: Ignores special OAuth scopes that control token behavior (like offline_access)
60+
* as they are not returned in the token response's scope list even when granted.
4961
*/
5062
export function getMissingRequiredScopes(
5163
credential: Credential | undefined,
5264
requiredScopes: string[] = []
5365
): string[] {
54-
if (!credential) return [...requiredScopes]
66+
if (!credential) {
67+
// Filter out ignored scopes from required scopes as they're not returned by OAuth providers
68+
return requiredScopes.filter((s) => !IGNORED_SCOPES.has(s))
69+
}
70+
5571
const granted = new Set((credential.scopes || []).map((s) => s))
5672
const missing: string[] = []
73+
5774
for (const s of requiredScopes) {
75+
// Skip ignored scopes as providers don't return them in the scope list even when granted
76+
if (IGNORED_SCOPES.has(s)) continue
77+
5878
if (!granted.has(s)) missing.push(s)
5979
}
80+
6081
return missing
6182
}
6283

apps/sim/tools/asana/add_comment.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const asanaAddCommentTool: ToolConfig<AsanaAddCommentParams, AsanaAddComm
1010
oauth: {
1111
required: true,
1212
provider: 'asana',
13-
additionalScopes: [],
1413
},
1514

1615
params: {

apps/sim/tools/asana/create_task.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const asanaCreateTaskTool: ToolConfig<AsanaCreateTaskParams, AsanaCreateT
1010
oauth: {
1111
required: true,
1212
provider: 'asana',
13-
additionalScopes: [],
1413
},
1514

1615
params: {

apps/sim/tools/asana/get_projects.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const asanaGetProjectsTool: ToolConfig<AsanaGetProjectsParams, AsanaGetPr
1010
oauth: {
1111
required: true,
1212
provider: 'asana',
13-
additionalScopes: [],
1413
},
1514

1615
params: {

apps/sim/tools/asana/get_task.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const asanaGetTaskTool: ToolConfig<AsanaGetTaskParams, AsanaGetTaskRespon
1010
oauth: {
1111
required: true,
1212
provider: 'asana',
13-
additionalScopes: [],
1413
},
1514

1615
params: {

apps/sim/tools/asana/search_tasks.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const asanaSearchTasksTool: ToolConfig<AsanaSearchTasksParams, AsanaSearc
1010
oauth: {
1111
required: true,
1212
provider: 'asana',
13-
additionalScopes: [],
1413
},
1514

1615
params: {

apps/sim/tools/asana/update_task.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const asanaUpdateTaskTool: ToolConfig<AsanaUpdateTaskParams, AsanaUpdateT
1010
oauth: {
1111
required: true,
1212
provider: 'asana',
13-
additionalScopes: [],
1413
},
1514

1615
params: {

apps/sim/tools/gmail/add_label.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const gmailAddLabelTool: ToolConfig<GmailLabelParams, GmailToolResponse>
1010
oauth: {
1111
required: true,
1212
provider: 'google-email',
13-
additionalScopes: ['https://www.googleapis.com/auth/gmail.modify'],
1413
},
1514

1615
params: {

apps/sim/tools/gmail/archive.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const gmailArchiveTool: ToolConfig<GmailMarkReadParams, GmailToolResponse
1010
oauth: {
1111
required: true,
1212
provider: 'google-email',
13-
additionalScopes: ['https://www.googleapis.com/auth/gmail.modify'],
1413
},
1514

1615
params: {

0 commit comments

Comments
 (0)