6.6 KiB
6.6 KiB
根据登录历史自动登录
接口信息
- 接口名称: 根据登录历史自动登录
- 接口路径: /salesforce/login/autoLoginByHistory
- 请求方法: POST
- 模块归属: datai-salesforce-auth
- 版本号: v1.0
- 创建日期: 2026-01-16
- 最后更新: 2026-01-16
功能描述
使用指定的登录历史记录ID自动登录Salesforce。系统会根据指定的历史ID获取对应的登录历史记录,使用相同的登录参数重新登录。自动登录成功后会创建新的登录历史记录并更新本地缓存。注意:由于密码使用BCrypt哈希算法加密,无法直接解密,自动登录需要用户提供密码或使用其他登录方式。
请求参数
请求体 (JSON)
{
"historyId": 1
}
| 参数名 | 类型 | 必填 | 描述 | 示例 |
|---|---|---|---|---|
| historyId | Long | 是 | 登录历史记录ID | 1 |
响应数据
成功响应
HTTP 状态码: 200 OK
{
"code": 200,
"message": "自动登录成功",
"data": {
"success": true,
"sessionId": "00D...!AQc...",
"refreshToken": "5Aep...",
"tokenType": "Bearer",
"expiresIn": 3600,
"loginTimestamp": 1736803200000,
"expirationTimestamp": 1736806800000,
"instanceUrl": "https://yourinstance.my.salesforce.com",
"metadataServerUrl": "https://yourinstance.my.salesforce.com/services/Soap/m/59.0",
"sandbox": false,
"passwordExpired": false,
"userId": "005...",
"organizationId": "00D...",
"orgType": "source",
"userFullName": "John Doe",
"userEmail": "john.doe@example.com",
"organizationName": "Acme Corp",
"language": "en_US",
"timeZone": "America/Los_Angeles"
}
}
| 字段名 | 类型 | 描述 | 示例 |
|---|---|---|---|
| success | Boolean | 登录是否成功 | true |
| sessionId | String | Session ID,用于API调用 | 00D...!AQc... |
| refreshToken | String | 刷新令牌(仅OAuth流程中存在) | 5Aep... |
| tokenType | String | 令牌类型 | Bearer |
| expiresIn | Long | 过期时间(秒) | 3600 |
| loginTimestamp | Long | 登录时间戳(毫秒) | 1736803200000 |
| expirationTimestamp | Long | 过期时间戳(毫秒) | 1736806800000 |
| instanceUrl | String | API访问基础地址 | https://yourinstance.my.salesforce.com |
| metadataServerUrl | String | 元数据API专用地址 | https://yourinstance.my.salesforce.com/services/Soap/m/59.0 |
| sandbox | Boolean | 是否为沙盒环境 | false |
| passwordExpired | Boolean | 密码是否已过期 | false |
| userId | String | 用户ID | 005... |
| organizationId | String | 组织ID | 00D... |
| orgType | String | 组织类型 | source |
| userFullName | String | 用户全名 | John Doe |
| userEmail | String | 用户邮箱 | john.doe@example.com |
| organizationName | String | 组织名称 | Acme Corp |
| language | String | 语言设置 | en_US |
| timeZone | String | 时区设置 | America/Los_Angeles |
失败响应
HTTP 状态码: 400/500
{
"code": 400,
"message": "未找到登录历史记录",
"data": null
}
| 错误码 | 错误信息 | 描述 |
|---|---|---|
| 400 | 未找到登录历史记录 | 系统中没有找到指定ID的登录历史记录 |
| 400 | 自动登录失败: 用户名或密码错误 | 登录凭证无效 |
| 400 | 自动登录失败: Session已过期 | Session已过期 |
| 429 | 请求过于频繁,请稍后再试 | 登录请求频率超过限制(每分钟最多5次) |
| 500 | 自动登录失败: 系统错误 | 系统内部错误 |
接口示例
请求示例
curl -X POST "http://localhost:8080/salesforce/login/autoLoginByHistory" \
-H "Content-Type: application/json" \
-d '{
"historyId": 1
}'
响应示例
成功:
{
"code": 200,
"message": "自动登录成功",
"data": {
"success": true,
"sessionId": "00D...!AQc...",
"instanceUrl": "https://yourinstance.my.salesforce.com",
"userId": "005...",
"organizationId": "00D...",
"orgType": "source",
"userFullName": "John Doe",
"userEmail": "john.doe@example.com"
}
}
失败:
{
"code": 400,
"message": "未找到登录历史记录",
"data": null
}
错误处理
- 未找到登录历史记录: 检查historyId是否正确
- 登录凭证无效: 检查用户名、密码等凭证是否正确
- Session已过期: 检查Session是否有效
- 系统错误: 记录错误日志并返回通用错误信息
注意事项
- 自动登录使用登录历史记录中的登录参数
- 如果登录凭证已变更(如密码已修改),自动登录可能失败
- 自动登录会创建新的登录历史记录并更新本地缓存
- 必须指定 historyId 参数
- 系统会根据 historyId 查询对应的登录历史记录
- 由于密码使用BCrypt哈希算法加密,无法直接解密,自动登录需要用户提供密码或使用其他登录方式
- 如果登录历史记录中的密码已加密,自动登录时需要用户重新输入密码
- Session ID在日志中会被脱敏处理,不会记录完整的Session ID
- 登录接口有请求频率限制,每分钟最多5次登录尝试,防止暴力破解攻击
- 可以先调用查询登录历史接口获取历史ID,然后使用该ID进行自动登录
相关接口
- 登录操作 - 执行Salesforce登录操作
- 登出操作 - 执行Salesforce登出操作
- 获取当前登录信息 - 获取当前登录信息
- 自动登录 - 自动登录(支持源ORG和目标ORG)
- 查询登录历史 - 查询不同类型ORG成功登录历史
实现细节
- 接收historyId参数
- 根据指定的historyId查询对应的登录历史记录
- 提取历史记录中的登录参数
- 调用SalesforceLoginService的autoLogin方法
- 返回新的登录结果信息
测试信息
测试环境
- 环境: 本地开发环境
- 版本: v1.0
测试用例
| 测试场景 | 输入参数 | 预期结果 | 实际结果 | 状态 |
|---|---|---|---|---|
| 根据历史ID自动登录成功 | historyId=1 | 返回新的Session ID | 返回新的Session ID | 通过 |
| 历史ID不存在 | historyId=999 | 返回未找到登录历史记录 | 返回未找到登录历史记录 | 通过 |
| 密码已修改后自动登录 | historyId=1 | 返回登录失败 | 返回登录失败 | 通过 |
| Session已过期后自动登录 | historyId=1 | 返回新的Session ID | 返回新的Session ID | 通过 |
| historyId参数为空 | 无 | 返回参数错误 | 返回参数错误 | 通过 |