获取用户是否有权访问应用
接口描述:
第三方平台可通该接口判断统一身份认证获取到的用户是否被授权访问当前接入的应用,通过该接口可做应用的访问控制实现。
接口地址:
请求方式:
- GET
请求头:
参数名称 | 参数说明 | 请求类型 | 是否必须 | 数据类型 | schema |
---|---|---|---|---|---|
X-App-Id | 客户端 clientId | header | true | string |
请求参数:
参数名称 | 参数说明 | 请求类型 | 是否必须 | 数据类型 | schema |
---|---|---|---|---|---|
accessToken | 接口访问凭证 | query | true | string | |
userId | 统一身份认证平台用户Id | query | true | long |
响应状态
状态码 | 说明 | schema |
---|---|---|
200 | OK | ApiRestResponse«AppPermissionVO» |
其他状态码参见:全局状态码
响应示例:
正确时返回:
{
"code": 200,
"status": "success",
"message": "请求成功",
"data": {
"hasAppPermission": true,
"userInfo": {
"account": "",
"email": "",
"gender": 0,
"nickname": "",
"roleList": [
{
"orgId": 0,
"roleCode": "",
"roleId": 0,
"roleName": ""
}
],
"thirdAccount": "",
"thirdUserId": 0,
"thirdUserName": ""
}
},
}
错误时返回:
{
"code": 500,
"data": {},
"message": "成功或异常消息",
"status": "fail"
}
响应参数:
参数名称 | 参数说明 | 类型 | schema |
---|---|---|---|
code | 成功或异常编码 | integer(int32) | integer(int32) |
data | 成功或异常数据 | array | AppVO |
message | 成功或异常消息 | string | |
status | 旧接口成功、失败或异常辅助判断标记:success、fail、error,可用值:success,fail,error | string |
Schema 属性:
AppPermissionVO
参数名称 | 参数说明 | 类型 | schema |
---|---|---|---|
hasAppPermission | 用户是否有当前应用的访问权限 | boolean | |
userInfo | 用户别名(昵称) | AppUserVO | AppUserVO |
@Data
public class AppPermissionVO {
/**
* 用户是否有当前应用的访问权限
*/
@ApiModelProperty(value = "用户是否有当前应用的访问权限")
private Boolean hasAppPermission;
/**
* 用户别名(昵称)
*/
@ApiModelProperty(value = "用户别名(昵称)")
private AppUserVO userInfo;
}
AppUserVO
参数名称 | 参数说明 | 类型 | schema |
---|---|---|---|
account | 登录账户 | string | |
电子邮箱 | string | ||
gender | 性别:(1:男,2:女) | integer(int32) | |
lastSequence | 上一次去数据后台返回给客户的Seq,初次拉取时为0 | integer(int64) | |
nickname | 用户别名(昵称) | string | |
thirdAccount | 绑定的三方账号 | string | |
thirdUserId | 绑定的三方用户Id | integer(int64) | |
thirdUserName | 绑定的三方用户名称 | string | |
roleList | 用户在该学校/组织机构下拥有的角色 | array | UserOrgRoleVO |
@Data
public class AppUserVO implements Serializable {
/**
* 用户id
*/
@ApiModelProperty(value = "用户id")
@JsonSerialize(using = ToStringSerializer.class)
private Long userId;
/**
* 用户别名(昵称)
*/
@ApiModelProperty(value = "用户别名(昵称)")
private String nickname;
/**
* 电子邮箱
*/
@ApiModelProperty(value = "电子邮箱")
private String email;
/**
* 性别:(1:男,2:女)
*/
@ApiModelProperty(value = "性别:(1:男,2:女)")
private Integer gender;
/**
* 登录账户
*/
@ApiModelProperty(value = "登录账户")
private String account;
/**
* 绑定的三方用户Id
*/
@ApiModelProperty(value = "绑定的三方用户Id")
private Long thirdUserId;
/**
* 绑定的三方账号
*/
@ApiModelProperty(value = "绑定的三方账号")
private String thirdAccount;
/**
* 绑定的三方用户名称
*/
@ApiModelProperty(value = "绑定的三方用户名称")
private String thirdUserName;
/**
* 用户在该学校/组织机构下拥有的角色
*/
@ApiModelProperty(value = "用户在该学校/组织机构下拥有的角色")
private List<UserOrgRoleVO> roleList;
/**
* 上一次去数据后台返回给客户的Seq,初次拉取时为0
*/
@ApiModelProperty(value = "上一次去数据后台返回给客户的Seq,初次拉取时为0")
private Long lastSequence;
@Override
public boolean equals(Object obj) {
if (obj instanceof AppUserVO) {
AppUserVO tmp = (AppUserVO) obj;
if (this.getUserId().equals(tmp.getUserId())) {
return true;
}
}
return false;
}
}
UserOrgRoleVO
参数名称 | 参数说明 | 类型 | schema |
---|---|---|---|
orgId | 角色授权机构ID | integer(int64) | |
roleCode | 角色编码 | string | |
roleId | 角色ID | integer(int64) | |
roleName | 角色名称 | string |
@Data
public class UserOrgRoleVO implements Serializable, Comparable<UserOrgRoleVO> {
private static final long serialVersionUID = 1L;
/**
* 用户id
*/
@ApiModelProperty(value = "用户id", hidden = true)
@JsonSerialize(using = ToStringSerializer.class)
@JsonIgnore
private Long userId;
@ApiModelProperty(value = "角色授权机构ID")
@JsonSerialize(using = ToStringSerializer.class)
private Long orgId;
@ApiModelProperty(value = "角色ID")
@JsonSerialize(using = ToStringSerializer.class)
private Long roleId;
@ApiModelProperty(value = "角色编码")
private String roleCode;
@ApiModelProperty(value = "角色名称")
private String roleName;
@Override
public int compareTo(UserOrgRoleVO obj) {
return this.getRoleId().compareTo(obj.getRoleId());
}
}
调用示例:
NodeJs - Axios:
var axios = require('axios');
var config = {
method: 'get',
url: 'https://api_server_url/app/hasPermission?accessToken=AT-3-ewOumlQeTN7TmVufJxq-Ph1fNVnqUTeW&userId=1542135022016057346',
headers: {
'X-App-Id': '1'
}
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
Java - OkHttp 示例:
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
.url("https://api_server_url/app/hasPermission?accessToken=AT-3-ewOumlQeTN7TmVufJxq-Ph1fNVnqUTeW&userId=1542135022016057346")
.method("GET", body)
.addHeader("X-App-Id", "1")
.build();
Response response = client.newCall(request).execute();
作者:杭州天音 创建时间:2022-10-27 14:49
最后编辑:杭州天音 更新时间:2025-08-22 15:44
最后编辑:杭州天音 更新时间:2025-08-22 15:44