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:
- 在 n8n 中为连接选择 Environment Type(Production 或 Sandbox)。
- 输入 Salesforce Username。
- 登录 Salesforce 组织。
- 准备由证书机构签发的私钥和证书。你可以使用已有证书,或用 OpenSSL 生成私钥和自签名证书。可参考 Salesforce 的创建私钥和自签名证书文档。
- 在 Salesforce 的 Setup 中搜索
App Manager并进入 App Manager。 - 选择 New External Client App。
- 填写 Basic Info(例如 Name、Contact Email address)。
- 在 API (Enable OAuth Settings) 中启用 Enable OAuth。
- 在 Callback URL 中填写
http://localhost:1717/OauthRedirect(自托管可填写你的 n8n 地址)。 - 在 OAuth Scopes 中添加:
- Full access (full)
- Perform requests at any time (refresh_token, offline_access)
- 在 Flow Enablement 中启用 Enable JWT Bearer Flow。
- 选择 Upload Files,上传数字证书文件(例如
server.crt)。 - 在 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
- 选择 Save,然后 Continue。
- 复制 Consumer Key,并在 n8n 凭据中填入 Client ID。
- 将私钥文件内容填入 n8n 的 Private Key(使用多行编辑器,PEM 格式)。
更多说明请参考 Salesforce 的 External Client App Basics。
创建 Connected App(旧版)#
旧版方法
Salesforce 正在弃用 Connected Apps。新的集成建议使用 External Client Apps。
- 在 n8n 中为连接选择 Environment Type(Production 或 Sandbox)。
- 输入 Salesforce Username。
- 登录 Salesforce 组织。
- 准备私钥和证书(可参考 Salesforce 的创建私钥和自签名证书文档)。
- 在 Setup 中搜索
App Manager并进入 App Manager。 - 选择 New Connected App。
- 填写 Basic Info(例如 Name、Contact Email address)。
- 勾选 Enable OAuth Settings。
- 在 Callback URL 中填写
http://localhost:1717/OauthRedirect。 - 勾选 Use digital signatures。
- 上传数字证书文件(例如
server.crt)。 - 添加 OAuth scopes:
- Full access (full)
- Perform requests at any time (refresh_token, offline_access)
- 选择 Save,然后 Continue。
- 在 API (Enable OAuth Settings) 中选择 Manage Consumer Details。
- 复制 Consumer Key,并填入 n8n 的 Client ID。
- 将私钥内容填入 n8n 的 Private Key(PEM 格式,多行输入)。
这些是 n8n 侧必需步骤。Salesforce 还建议设置刷新令牌、会话和 OAuth 策略:
- 返回 Manage Connected Apps。
- 选择 Manage。
- 选择 Edit Policies。
- 查看 Refresh Token Policy(建议 90 天过期)。
- 在 Session Policies 中将 Timeout Value 设为 15 分钟。
- 在 OAuth Policies 中将 Permitted Users 设为 Admin approved users are pre-authorized for permitted users,然后选择 OK。
- 选择 Save。
- 进入 Manage Profiles,选择预授权配置并保存。
- 进入 Manage Permission Sets,选择(或创建)权限集。
请参考 Salesforce 的在组织中创建 Connected App 文档。
使用 OAuth2#
要配置此凭据,您需要一个 Salesforce 账户。
您需要选择您的 Environment Type 环境类型。在 Production 和 Sandbox 之间选择。
创建 External Client App(推荐)#
如果您是自托管 n8n,需要自行创建 OAuth2 配置。推荐使用 External Client App:
- 在 n8n 中,为您的连接选择 Environment Type(Production 或 Sandbox)。
- 输入您的 Salesforce Username。
- 登录您的 Salesforce 组织。
- 在 Salesforce 的 Setup 中,在 Quick Find 框中输入
App Manager,然后选择 App Manager。 - 在 App Manager 页面中,选择 New External Client App。
- 输入 External Client App 所需的 Basic Info,包括 Name 和 Contact Email address。
- 在 API (Enable OAuth Settings) 下,选择 Enable OAuth。
- 在 Callback URL 框中,添加您的 n8n OAuth 回调 URL(例如
https://your-n8n-instance.com/rest/oauth2-credential/callback。对于 n8n Cloud,URL 为https://oauth.n8n.cloud/oauth2/callback)。 - 在 OAuth Scopes 部分,选择以下范围:
- Full access (full)
- Perform requests at any time (refresh_token, offline_access)
- 在 Flow Enablement 部分,选择 Enable Authorization Code and Credentials Flow。
- 在 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
- 选择 Save,然后 Continue。
- 复制 Consumer Key 填入 n8n 的 Client ID。
- 复制 Consumer Secret 填入 n8n 的 Client Secret。
更多说明请参考 Salesforce 的 External Client App Basics。
创建 Connected App(旧版)#
旧版方法
Salesforce 正在弃用 Connected Apps。新的集成建议使用 External Client Apps。
如果您自托管 n8n,也可以通过 Connected App 配置 OAuth2:
- 在 n8n 中选择 Environment Type,并输入 Salesforce Username。
- 登录 Salesforce 组织,在 Setup 中进入 App Manager。
- 选择 New Connected App 并填写 Basic Info。
- 勾选 Enable OAuth Settings,并在 Callback URL 中填写
http://localhost:1717/OauthRedirect。 - 添加 OAuth scopes:
- Full access (full)
- Perform requests at any time (refresh_token, offline_access)
- 确保以下设置未勾选:
- Require Proof Key for Code Exchange (PKCE) Extension for Supported Authorization Flows
- Require Secret for Web Server Flow
- Require Secret for Refresh Token Flow
- 选择 Save,然后 Continue。
- 在 API (Enable OAuth Settings) 中选择 Manage Consumer Details。
- 复制 Consumer Key 到 n8n 的 Client ID。
- 复制 Consumer Secret 到 n8n 的 Client Secret。
这些是 n8n 侧必需步骤。Salesforce 还建议设置刷新令牌和会话策略:
- 返回 Manage Connected Apps 并选择 Manage。
- 选择 Edit Policies。
- 查看 Refresh Token Policy(建议 90 天过期)。
- 在 Session Policies 中将 Timeout Value 设为 15 分钟。
请参考 Salesforce 的在组织中创建 Connected App 文档。
Common issues 常见问题#
Connection issues when authenticating with Salesforce from n8n Cloud 从 n8n 云版本使用 Salesforce 进行身份验证时的连接问题#
如果您在从 n8n 云版本使用 Salesforce 进行身份验证时遇到连接问题,您可能需要在 Salesforce 用户配置文件中启用特定的系统权限:
- 在 Salesforce 中,进入 Setup 设置。
- 在 Quick Find 快速查找框中,搜索
Profiles。 - 选择连接到 n8n 的用户使用的配置文件(例如,System Administrator 或相关配置文件)。
- 点击 Edit 编辑或使用新的 Profile 配置文件界面(如果可用)。
- 找到 Administrative Permissions 管理权限部分。
- 启用 Approve Connected Apps for Non-Admins 为非管理员批准连接应用的复选框。此复选框也可能显示为 Approve apps connected not installed 批准未安装的已连接应用,具体取决于您的 Salesforce 语言或翻译。
- 点击 Save 保存。
此权限默认情况下未启用,即使对于管理员配置文件也是如此,必须手动激活。如果没有此权限,您在尝试将 n8n 连接到 Salesforce 时可能会遇到身份验证失败。