Skip to content

Salesforce 凭据#

您可以使用这些凭据来验证以下节点:

支持的认证方法#

  • JWT
  • OAuth2

相关资源#

参考 Salesforce 的开发者文档了解有关该服务的更多信息。

Salesforce External Client Apps

Salesforce 正在逐步弃用 Connected Apps,转向 External Client Apps。两种方式都可以与 n8n 配合使用;如果是新建集成,建议优先使用 External Client Apps。

使用 JWT#

要配置此凭据,您需要一个 Salesforce 账户和:

  • 您的 Environment Type 环境类型(Production 或 Sandbox)
  • 一个 Client ID 客户端 ID:在创建 External Client App 或 Connected App 时生成。
  • 您的 Salesforce Username 用户名
  • 用于自签名数字证书的 Private Key 私钥

创建 External Client App(推荐)#

要完成配置,先准备私钥和证书,再创建 External Client App:

  1. 在 n8n 中为连接选择 Environment TypeProductionSandbox)。
  2. 输入 Salesforce Username
  3. 登录 Salesforce 组织。
  4. 准备由证书机构签发的私钥和证书。你可以使用已有证书,或用 OpenSSL 生成私钥和自签名证书。可参考 Salesforce 的创建私钥和自签名证书文档
  5. 在 Salesforce 的 Setup 中搜索 App Manager 并进入 App Manager
  6. 选择 New External Client App
  7. 填写 Basic Info(例如 NameContact Email address)。
  8. API (Enable OAuth Settings) 中启用 Enable OAuth
  9. Callback URL 中填写 http://localhost:1717/OauthRedirect(自托管可填写你的 n8n 地址)。
  10. OAuth Scopes 中添加:
    • Full access (full)
    • Perform requests at any time (refresh_token, offline_access)
  11. Flow Enablement 中启用 Enable JWT Bearer Flow
  12. 选择 Upload Files,上传数字证书文件(例如 server.crt)。
  13. OAuth Policies 中确保以下选项为未勾选:
    • Require Secret for Web Server Flow
    • Require Secret for Refresh Token Flow
    • Require Proof Key for Code Exchange (PKCE) Extension for Supported Authorization Flows
  14. 选择 Save,然后 Continue
  15. 复制 Consumer Key,并在 n8n 凭据中填入 Client ID
  16. 将私钥文件内容填入 n8n 的 Private Key(使用多行编辑器,PEM 格式)。

更多说明请参考 Salesforce 的 External Client App Basics

创建 Connected App(旧版)#

旧版方法

Salesforce 正在弃用 Connected Apps。新的集成建议使用 External Client Apps。

  1. 在 n8n 中为连接选择 Environment TypeProductionSandbox)。
  2. 输入 Salesforce Username
  3. 登录 Salesforce 组织。
  4. 准备私钥和证书(可参考 Salesforce 的创建私钥和自签名证书文档)。
  5. Setup 中搜索 App Manager 并进入 App Manager
  6. 选择 New Connected App
  7. 填写 Basic Info(例如 NameContact Email address)。
  8. 勾选 Enable OAuth Settings
  9. Callback URL 中填写 http://localhost:1717/OauthRedirect
  10. 勾选 Use digital signatures
  11. 上传数字证书文件(例如 server.crt)。
  12. 添加 OAuth scopes
    • Full access (full)
    • Perform requests at any time (refresh_token, offline_access)
  13. 选择 Save,然后 Continue
  14. API (Enable OAuth Settings) 中选择 Manage Consumer Details
  15. 复制 Consumer Key,并填入 n8n 的 Client ID
  16. 将私钥内容填入 n8n 的 Private Key(PEM 格式,多行输入)。

这些是 n8n 侧必需步骤。Salesforce 还建议设置刷新令牌、会话和 OAuth 策略:

  1. 返回 Manage Connected Apps
  2. 选择 Manage
  3. 选择 Edit Policies
  4. 查看 Refresh Token Policy(建议 90 天过期)。
  5. Session Policies 中将 Timeout Value 设为 15 分钟。
  6. OAuth Policies 中将 Permitted Users 设为 Admin approved users are pre-authorized for permitted users,然后选择 OK
  7. 选择 Save
  8. 进入 Manage Profiles,选择预授权配置并保存。
  9. 进入 Manage Permission Sets,选择(或创建)权限集。

请参考 Salesforce 的在组织中创建 Connected App 文档

使用 OAuth2#

要配置此凭据,您需要一个 Salesforce 账户。

您需要选择您的 Environment Type 环境类型。在 ProductionSandbox 之间选择。

创建 External Client App(推荐)#

如果您是自托管 n8n,需要自行创建 OAuth2 配置。推荐使用 External Client App:

  1. 在 n8n 中,为您的连接选择 Environment TypeProductionSandbox)。
  2. 输入您的 Salesforce Username
  3. 登录您的 Salesforce 组织。
  4. 在 Salesforce 的 Setup 中,在 Quick Find 框中输入 App Manager,然后选择 App Manager
  5. 在 App Manager 页面中,选择 New External Client App
  6. 输入 External Client App 所需的 Basic Info,包括 NameContact Email address
  7. API (Enable OAuth Settings) 下,选择 Enable OAuth
  8. Callback URL 框中,添加您的 n8n OAuth 回调 URL(例如 https://your-n8n-instance.com/rest/oauth2-credential/callback。对于 n8n Cloud,URL 为 https://oauth.n8n.cloud/oauth2/callback)。
  9. OAuth Scopes 部分,选择以下范围:
    • Full access (full)
    • Perform requests at any time (refresh_token, offline_access)
  10. Flow Enablement 部分,选择 Enable Authorization Code and Credentials Flow
  11. OAuth Policies 下,确保以下设置已勾选
    • Require Secret for Web Server Flow
    • Require Secret for Refresh Token Flow
    • Require Proof Key for Code Exchange (PKCE) Extension for Supported Authorization Flows
  12. 选择 Save,然后 Continue
  13. 复制 Consumer Key 填入 n8n 的 Client ID
  14. 复制 Consumer Secret 填入 n8n 的 Client Secret

更多说明请参考 Salesforce 的 External Client App Basics

创建 Connected App(旧版)#

旧版方法

Salesforce 正在弃用 Connected Apps。新的集成建议使用 External Client Apps。

如果您自托管 n8n,也可以通过 Connected App 配置 OAuth2:

  1. 在 n8n 中选择 Environment Type,并输入 Salesforce Username
  2. 登录 Salesforce 组织,在 Setup 中进入 App Manager
  3. 选择 New Connected App 并填写 Basic Info
  4. 勾选 Enable OAuth Settings,并在 Callback URL 中填写 http://localhost:1717/OauthRedirect
  5. 添加 OAuth scopes
    • Full access (full)
    • Perform requests at any time (refresh_token, offline_access)
  6. 确保以下设置未勾选:
    • Require Proof Key for Code Exchange (PKCE) Extension for Supported Authorization Flows
    • Require Secret for Web Server Flow
    • Require Secret for Refresh Token Flow
  7. 选择 Save,然后 Continue
  8. API (Enable OAuth Settings) 中选择 Manage Consumer Details
  9. 复制 Consumer Key 到 n8n 的 Client ID
  10. 复制 Consumer Secret 到 n8n 的 Client Secret

这些是 n8n 侧必需步骤。Salesforce 还建议设置刷新令牌和会话策略:

  1. 返回 Manage Connected Apps 并选择 Manage
  2. 选择 Edit Policies
  3. 查看 Refresh Token Policy(建议 90 天过期)。
  4. Session Policies 中将 Timeout Value 设为 15 分钟。

请参考 Salesforce 的在组织中创建 Connected App 文档

Common issues 常见问题#

Connection issues when authenticating with Salesforce from n8n Cloud 从 n8n 云版本使用 Salesforce 进行身份验证时的连接问题#

如果您在从 n8n 云版本使用 Salesforce 进行身份验证时遇到连接问题,您可能需要在 Salesforce 用户配置文件中启用特定的系统权限:

  1. 在 Salesforce 中,进入 Setup 设置
  2. Quick Find 快速查找框中,搜索 Profiles
  3. 选择连接到 n8n 的用户使用的配置文件(例如,System Administrator 或相关配置文件)。
  4. 点击 Edit 编辑或使用新的 Profile 配置文件界面(如果可用)。
  5. 找到 Administrative Permissions 管理权限部分。
  6. 启用 Approve Connected Apps for Non-Admins 为非管理员批准连接应用的复选框。此复选框也可能显示为 Approve apps connected not installed 批准未安装的已连接应用,具体取决于您的 Salesforce 语言或翻译。
  7. 点击 Save 保存

此权限默认情况下未启用,即使对于管理员配置文件也是如此,必须手动激活。如果没有此权限,您在尝试将 n8n 连接到 Salesforce 时可能会遇到身份验证失败。