Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

@waleedlatif1 waleedlatif1 commented Dec 18, 2025

This reverts commit 9da19e8.

…roduction, developer, and custom domain salesforce orgs (#2441) (#2444)"

This reverts commit 9da19e8.
@vercel
Copy link

vercel bot commented Dec 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Dec 18, 2025 8:31pm

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 18, 2025

Greptile Summary

  • Reverts Salesforce OAuth enhancement that supported production, developer, and custom domain orgs, returning to standard OAuth2 flow
  • Removes specialized Salesforce OAuth endpoints and callback handlers, replacing with hardcoded login.salesforce.com configuration
  • Inlines JWT token parsing logic across multiple Salesforce tools instead of using shared utility functions

Important Files Changed

Filename Overview
apps/sim/app/api/auth/salesforce/authorize/route.ts Entire file deleted - removes custom Salesforce OAuth authorization handler with org selection
apps/sim/app/api/auth/oauth2/callback/salesforce/route.ts Entire file deleted - removes Salesforce OAuth2 callback endpoint, breaking authentication flow
apps/sim/lib/auth/auth.ts Reverts to hardcoded Salesforce OAuth configuration using login.salesforce.com only
apps/sim/lib/oauth/oauth.ts Removes flexible multi-endpoint Salesforce token refresh logic and simplifies function signature
apps/sim/tools/salesforce/*.ts Multiple tools revert to inline JWT parsing instead of shared utility functions

Confidence score: 1/5

  • This PR introduces breaking changes by completely removing OAuth callback endpoints without replacement
  • Multiple Salesforce authentication flows will fail due to missing API endpoints and routes
  • Pay close attention to apps/sim/app/api/auth/oauth2/callback/salesforce/route.ts and apps/sim/app/api/auth/salesforce/authorize/route.ts - both files are empty/deleted

Sequence Diagram

sequenceDiagram
    participant User
    participant SimStudio as "SimStudio App"
    participant DB as "Database"
    participant SalesforceAuth as "Salesforce OAuth"
    participant SalesforceAPI as "Salesforce API"

    User->>SimStudio: "Initiate OAuth connection"
    SimStudio->>SalesforceAuth: "Redirect to authorization endpoint"
    User->>SalesforceAuth: "Authorize application"
    SalesforceAuth->>SimStudio: "Return authorization code"
    SimStudio->>SalesforceAuth: "Exchange code for tokens"
    SalesforceAuth->>SimStudio: "Return access token, refresh token, ID token"
    SimStudio->>DB: "Store OAuth credentials"
    
    User->>SimStudio: "Execute Salesforce tool"
    SimStudio->>DB: "Retrieve stored credentials"
    alt Token expired
        SimStudio->>SalesforceAuth: "Refresh token request"
        SalesforceAuth->>SimStudio: "Return new access token"
        SimStudio->>DB: "Update stored tokens"
    end
    SimStudio->>SimStudio: "Extract instance URL from ID token"
    SimStudio->>SalesforceAPI: "API request with access token"
    SalesforceAPI->>SimStudio: "Return API response"
    SimStudio->>User: "Return processed results"
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (2)

  1. apps/sim/app/api/auth/oauth2/callback/salesforce/route.ts

    logic: Complete removal of Salesforce OAuth callback handler will break all Salesforce authentication flows. The /api/auth/oauth2/callback/salesforce endpoint will return 404, causing OAuth failures. Is there a replacement callback handler being implemented, or should this revert to a previous working version instead of complete deletion?

  2. apps/sim/tools/salesforce/utils.ts, line 46 (link)

    style: Using any type instead of proper TypeScript typing

    Context Used: Context from dashboard - TypeScript conventions and type safety (source)

12 files reviewed, 5 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +157 to +183
if (!instanceUrl && params.idToken) {
try {
const base64Url = params.idToken.split('.')[1]
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/')
const jsonPayload = decodeURIComponent(
atob(base64)
.split('')
.map((c) => `%${(`00${c.charCodeAt(0).toString(16)}`).slice(-2)}`)
.join('')
)
const decoded = JSON.parse(jsonPayload)

if (decoded.profile) {
const match = decoded.profile.match(/^(https:\/\/[^/]+)/)
if (match) {
instanceUrl = match[1]
}
} else if (decoded.sub) {
const match = decoded.sub.match(/^(https:\/\/[^/]+)/)
if (match && match[1] !== 'https://login.salesforce.com') {
instanceUrl = match[1]
}
}
} catch (error) {
logger.error('Failed to decode Salesforce idToken', { error })
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: JWT token parsing logic now duplicated across multiple Salesforce tools. Should this logic be extracted to a shared utility to avoid duplication across other Salesforce tools?

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/tools/salesforce/update_account.ts
Line: 157:183

Comment:
**style:** JWT token parsing logic now duplicated across multiple Salesforce tools. Should this logic be extracted to a shared utility to avoid duplication across other Salesforce tools?

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +153 to +160
const base64Url = params.idToken.split('.')[1]
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/')
const jsonPayload = decodeURIComponent(
atob(base64)
.split('')
.map((c) => `%${(`00${c.charCodeAt(0).toString(16)}`).slice(-2)}`)
.join('')
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Complex JWT decoding logic should be extracted to a utility function for reuse across Salesforce tools

Context Used: Context from dashboard - Core architecture principles for the Sim app (source). Was there a specific issue with the centralized getInstanceUrl utility that required this reversion?

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/tools/salesforce/create_account.ts
Line: 153:160

Comment:
**style:** Complex JWT decoding logic should be extracted to a utility function for reuse across Salesforce tools

**Context Used:** Context from `dashboard` - Core architecture principles for the Sim app ([source](https://app.greptile.com/review/custom-context?memory=2d6e479d-8e35-4102-a11d-13cf026616dd)). Was there a specific issue with the centralized `getInstanceUrl` utility that required this reversion?

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +67 to +93
if (!instanceUrl && params.idToken) {
try {
const base64Url = params.idToken.split('.')[1]
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/')
const jsonPayload = decodeURIComponent(
atob(base64)
.split('')
.map((c) => `%${(`00${c.charCodeAt(0).toString(16)}`).slice(-2)}`)
.join('')
)
const decoded = JSON.parse(jsonPayload)

if (decoded.profile) {
const match = decoded.profile.match(/^(https:\/\/[^/]+)/)
if (match) {
instanceUrl = match[1]
}
} else if (decoded.sub) {
const match = decoded.sub.match(/^(https:\/\/[^/]+)/)
if (match && match[1] !== 'https://login.salesforce.com') {
instanceUrl = match[1]
}
}
} catch (error) {
logger.error('Failed to decode Salesforce idToken', { error })
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: This complex JWT parsing logic appears to be duplicated across multiple Salesforce tools. Consider extracting to a shared utility function to improve maintainability.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/tools/salesforce/get_accounts.ts
Line: 67:93

Comment:
**style:** This complex JWT parsing logic appears to be duplicated across multiple Salesforce tools. Consider extracting to a shared utility function to improve maintainability.

<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>

How can I resolve this? If you propose a fix, please make it concise.

@waleedlatif1 waleedlatif1 merged commit c23130a into staging Dec 18, 2025
11 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/sf branch December 18, 2025 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants