时序图
对接接口
功能:获取用户信息接口对接
测试服务地址:http://pai.flyrise.cn/auth-api (根据实际环境替换)
请求地址: /oauth2/user
请求类型:POST
请求参数:Header
名称 | 类型 | 是否必须 |
---|---|---|
Authorization | Header | true |
token 请求示例: Authorization: bearer c6862aca-0e0e-48f8-bfd4-823d4edc903d
回应结果:
回应参数说明:
名称 | 类型 | 备注 |
---|---|---|
username | string | 用户名 |
authorities | list | 权限列表 |
userId | string | 用户id |
entId | string | 当前企业id |
{
"code": "200",
"data": {
"password": null,
"username": "admin",
"authorities": [
{
"authority": "ROLE_normal"
}
],
"accountNonExpired": true,
"accountNonLocked": true,
"credentialsNonExpired": true,
"enabled": true,
"userId": "1810146045832466432",
"nickName": "xxx",
"deptId": "1810146259880382464",
"entId": "1810146256491384832",
"platform": "workbench",
"openId": null,
"parkId": null,
"parkCode": null,
"parkName": null,
"deptName": "珠海研发",
"entName": "开发区事业部",
"staffId": "1810146259901353984",
"staffName": "xxx",
"phoneNumber": "186****0169",
"version": null,
"avatar": "",
"status": "0",
"loginIp": "10.62.1.104",
"loginOs": "Windows 10",
"loginPlace": "内网",
"loginTime": "2024-07-16T09:46:46.758+08:00",
"loginBrowser": "Chrome 12",
"referer": "http://10.62.1.104:8080/auth/?type=workbench&url=http%3A%2F%2F10.62.1.104%3A8080%2Fworkbench&showPage=account"
},
"time": 1721095294577,
"msg": "操作成功",
"annex": null,
"success": true,
"ok": true
}
接入步骤
门户配置
进入企业档案-其他配置-应用入口配置
点击新增,填入应用名称和登录跳转接口(自己定义)并保存
- 此时可在统一门户看见新配置的应用
- 点击进入,会自动跳转并带上token(可能存在token泄露风险)
http://112.132.240.253:19090/sso/login?token=c0ca448e-a676-4a5b-9962-d3dc39ef3c82
第三方开发接入
- 定义一个登录跳转接口(接口路径与上述配置的接口路径保持一致):
@GET
@Path("/sso/login")
public void ssoLogin(@QueryParam("token") String token, HttpServletResponse response) {
userLogic.ssoLogin(token, response);
}
public void ssoLogin(String token, HttpServletResponse response) throws IOException {
Map<String, String> map = new HashMap(2);
if (StringUtils.isNotBlank(token)) {
HashMap<String, String> headerMap = new HashMap<>();
headerMap.put("Authorization", "Bearer " + token);
//请求http://pai.flyrise.cn/auth-api/oauth2/user(根据实际环境替换)
String reultForHttpPost = HttpUtil.getReultForHttpPost(LingyunSsoProperties.getGetUserInfoApi(), null, headerMap);
JSONObject jsonObject = JSONUtil.parseObj(reultForHttpPost);
int code = jsonObject.getInt("code");
if (code == 200) {
JSONObject data = jsonObject.getJSONObject("data");
LingyunUser lingyunUser = JSONUtil.toBean(data, LingyunUser.class);
FieldSet fs = this.userHelperImpl.getUserByName(lingyunUser.getUserName());
if (fs == null) {
//如果用户为空,新建用户
}
//...走登录成功逻辑...
response.sendRedirect(url);
} else {
//...获取中台用户信息失败...
LogUtils.error("获取中台用户信息失败,错误[{}]" + jsonObject.toString());
}
} else {
//...token为空...
LogUtils.error("token为空,登录失败");
}
}
文档更新时间: 2024-07-17 09:04 作者:欧阳少海