n8n 中文文档

Salesforce 凭证

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

支持的认证方式

  • JWT
  • OAuth2

相关资源

有关该服务的更多信息,请参阅 Salesforce 开发者文档{:target=_blank .external-link}。

警告

Feature availability 功能可用性

Salesforce 正在弃用 Connected Apps,转而使用 External Client Apps。请查看 Salesforce 官方文档了解退役时间表。两种方法都适用于 n8n。如果你要创建新的集成,请使用 External Client Apps。现有的 Connected Apps 将继续工作。

使用 JWT

要配置此凭据,您需要一个 Salesforce{:target=_blank .external-link} 账户和:

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

创建外部客户端应用程序(推荐)

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

  1. 在 n8n 中为连接选择 Environment Type(Production 或 Sandbox)。
  2. 输入 Salesforce Username。
  3. 登录 Salesforce 组织。
  4. 准备由证书机构签发的私钥和证书。你可以使用已有证书,或用 OpenSSL 生成私钥和自签名证书。可参考 Salesforce 的创建私钥和自签名数字证书文档{:target=_blank .external-link},了解如何创建私钥和证书。
  5. 在 Salesforce 的 Setup 中,在快速查找框中输入 App Manager,然后选择 App Manager。
  6. 在 App Manager 页面中选择 New External Client App。
  7. 填写 External Client App 所需的 Basic Info,包括 Name 和 Contact Email address。
  8. 在 API (Enable OAuth Settings) 下选择 Enable OAuth。
  9. 在 Callback URL 框中添加回调 URL:http://localhost:1717/OauthRedirect(如果是自托管,也可以填写你的 n8n 实例 URL)。
  10. 在 OAuth Scopes 部分选择以下范围:
    • Full access (full) 完全访问(full)
    • Perform requests at any time (refresh_token, offline_access) 随时执行请求(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 Web 服务器流程需要机密
    • Require Secret for Refresh Token Flow 刷新令牌流需要机密
    • Require Proof Key for Code Exchange (PKCE) Extension for Supported Authorization Flows 需要代码交换证明密钥 (PKCE) 扩展才能支持授权流程
  14. 选择 Save,然后选择 Continue。
  15. 复制 Consumer Key,并将其作为 Client ID 添加到 n8n 凭据中。
  16. 将私钥文件的内容填入 n8n 凭据的 Private Key 字段。
    • 在 n8n 中使用多行编辑器。
    • 以标准 PEM key 格式输入私钥:

      -----BEGIN PRIVATE KEY----- KEY DATA GOES HERE -----END PRIVATE KEY-----

更多信息请参阅 Salesforce 的 External Client App Basics{:target=_blank .external-link} 文档。

创建连接的应用程序(旧版)

警告

Feature availability 功能可用性

Salesforce 正在弃用 Connected Apps,转而使用 External Client Apps。请查看 Salesforce 官方文档了解退役时间表。新集成请改用 External Client Apps。

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

  1. 在 n8n 中为连接选择 Environment Type(Production 或 Sandbox)。
  2. 输入 Salesforce Username。
  3. 登录 Salesforce 组织。
  4. 准备由证书机构签发的私钥和证书。你可以使用已有证书,或用 OpenSSL 生成私钥和自签名证书。可参考 Salesforce 的创建私钥和自签名数字证书文档{:target=_blank .external-link},了解如何创建私钥和证书。
  5. 在 Salesforce 的 Setup 中,在快速查找框中输入 App Manager,然后选择 App Manager。
  6. 在 App Manager 页面中选择 New Connected App。
  7. 填写 Connected App 所需的 Basic Info,包括 Name 和 Contact Email address。更多信息请参阅 Salesforce 的配置 Connected App 基本设置{:target=_blank .external-link}文档。
  8. 勾选 Enable OAuth Settings。
  9. 在 Callback URL 中输入 http://localhost:1717/OauthRedirect。
  10. 勾选 Use digital signatures。
  11. 选择 Choose File,上传包含数字证书的文件,例如 server.crt。
  12. 添加以下 OAuth scopes:
    • Full access (full) 完全访问(full)
    • Perform requests at any time (refresh_token, offline_access) 随时执行请求(refresh_token、offline_access)
  13. 选择 Save,然后选择 Continue。此时应打开刚创建应用的 Manage Connected Apps 页面。
  14. 在 API (Enable OAuth Settings) 部分选择 Manage Consumer Details。
  15. 复制 Consumer Key,并将其作为 Client ID 添加到 n8n 凭据中。
  16. 将私钥文件的内容填入 n8n 凭据的 Private Key 字段。
    • 在 n8n 中使用多行编辑器。
    • 以标准 PEM key 格式输入私钥:

      -----BEGIN PRIVATE KEY----- KEY DATA GOES HERE -----END PRIVATE KEY-----

以上是 n8n 侧所需的步骤。Salesforce 还建议设置刷新令牌策略、会话策略和 OAuth 策略:

  1. 在 Salesforce 中选择 Back to Manage Connected Apps。
  2. 选择 Manage。
  3. 选择 Edit Policies。
  4. 查看 Refresh Token Policy 字段。Salesforce 建议设置为 90 天后使刷新令牌过期。
  5. 在 Session Policies 部分,Salesforce 建议将 Timeout Value 设置为 15 分钟。
  6. 在 OAuth Policies 部分,将 Permitted Users 设置为 Admin approved users are pre-authorized for permitted users,然后选择 OK。
  7. 选择 Save。
  8. 选择 Manage Profiles,选择预授权使用此 Connected App 的配置文件,然后选择 Save。
  9. 选择 Manage Permission Sets 以选择权限集。如有需要,请创建权限集。

更多信息请参阅 Salesforce 的在组织中创建 Connected App{:target=_blank .external-link}文档。

使用 OAuth2

要配置此凭据,您需要一个 Salesforce{:target=_blank .external-link} 账户。

您需要选择 Environment Type,在 Production 和 Sandbox 之间选择。

创建外部客户端应用程序(推荐)

如果您是自托管 n8n,则需要通过创建 External Client App 从头开始配置 OAuth2:

  1. 在 n8n 中为连接选择 Environment Type(Production 或 Sandbox)。
  2. 输入 Salesforce Username。
  3. 登录 Salesforce 组织。
  4. 在 Salesforce 的 Setup 中,在快速查找框中输入 App Manager,然后选择 App Manager。
  5. 在 App Manager 页面中选择 New External Client App。
  6. 填写 External Client App 所需的 Basic Info,包括 Name 和 Contact 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) 完全访问(full)
    • Perform requests at any time (refresh_token, offline_access) 随时执行请求(refresh_token、offline_access)
  10. 在 Flow Enablement 部分选择 Enable Authorization Code and Credentials Flow。
  11. 在 OAuth Policies 下,确保以下设置均已勾选:
    • Require Secret for Web Server Flow Web 服务器流程需要机密
    • Require Secret for Refresh Token Flow 刷新令牌流需要机密
    • Require Proof Key for Code Exchange (PKCE) Extension for Supported Authorization Flows 需要代码交换证明密钥 (PKCE) 扩展才能支持授权流程
  12. 选择 Save,然后选择 Continue。
  13. 复制 Consumer Key,并将其作为 Client ID 添加到 n8n 凭据中。
  14. 复制 Consumer Secret,并将其作为 Client Secret 添加到 n8n 凭据中。

更多信息请参阅 Salesforce 的 External Client App Basics{:target=_blank .external-link} 文档。

创建连接的应用程序(旧版)

警告

Feature availability 功能可用性

Salesforce 正在弃用 Connected Apps,转而使用 External Client Apps。请查看 Salesforce 官方文档了解退役时间表。新集成请改用 External Client Apps。

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

  1. 在 n8n 中为连接选择 Environment Type(Production 或 Sandbox)。
  2. 输入 Salesforce Username。
  3. 登录 Salesforce 组织。
  4. 在 Salesforce 的 Setup 中,在快速查找框中输入 App Manager,然后选择 App Manager。
  5. 在 App Manager 页面中选择 New Connected App。
  6. 填写 Connected App 所需的 Basic Info,包括 Name 和 Contact Email address。更多信息请参阅 Salesforce 的配置 Connected App 基本设置{:target=_blank .external-link}文档。
  7. 勾选 Enable OAuth Settings。
  8. 在 Callback URL 中输入 http://localhost:1717/OauthRedirect。
  9. 添加以下 OAuth scopes:
    • Full access (full) 完全访问(full)
    • Perform requests at any time (refresh_token, offline_access) 随时执行请求(refresh_token、offline_access)
  10. 确保以下设置均未勾选:
    • Require Proof Key for Code Exchange (PKCE) Extension for Supported Authorization Flows 需要代码交换证明密钥 (PKCE) 扩展才能支持授权流程
    • Require Secret for Web Server Flow Web 服务器流程需要机密
    • Require Secret for Refresh Token Flow 刷新令牌流需要机密
  11. 选择 Save,然后选择 Continue。此时应打开刚创建应用的 Manage Connected Apps 页面。
  12. 在 API (Enable OAuth Settings) 部分选择 Manage Consumer Details。
  13. 复制 Consumer Key,并将其作为 Client ID 添加到 n8n 凭据中。
  14. 复制 Consumer Secret,并将其作为 Client Secret 添加到 n8n 凭据中。

以上是 n8n 侧所需的步骤。Salesforce 还建议设置刷新令牌策略和会话策略:

  1. 在 Salesforce 中选择 Back to Manage Connected Apps。
  2. 选择 Manage。
  3. 选择 Edit Policies。
  4. 查看 Refresh Token Policy 字段。Salesforce 建议设置为 90 天后使刷新令牌过期。
  5. 在 Session Policies 部分,Salesforce 建议将 Timeout Value 设置为 15 分钟。

更多信息请参阅 Salesforce 的在组织中创建 Connected App{:target=_blank .external-link}文档。

常见问题

从 n8n Cloud 向 Salesforce 进行身份验证时出现连接问题

如果您从 n8n Cloud 向 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。根据 Salesforce 的语言或翻译,此复选框也可能显示为 Approve apps connected not installed。
  7. 选择 Save。

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

不想自己部署和维护 n8n?n8ncn 托管 n8n 云服务:开通账号即可使用,不用买服务器;也可以在 n8ncn 工作流库 找现成的中文工作流。