¶ 管理用户
此模块可以进行用户目录增删改查、搜索用户、管理用户分组、管理用户角色、管理用户策略授权等操作。
请通过以下方式使用该模块:
client := NewClient(userPoolId, secret)
client.ListUser() # 获取用户列表
client.CreateUser() # 创建用户
¶ 创建用户
此接口将以管理员身份创建用户,不需要进行手机号验证码检验等安全检测。用户的手机号、邮箱、用户名、externalId 用户池内唯一
// CreateUser
// 创建用户
func (c *Client) CreateUser(request model.CreateUserRequest) (*model.User, error)
¶ 参数
request
<CreateUserRequest> 用户资料CreateUserRequest.Email
<string> 邮箱,用户池内唯一CreateUserRequest.EmailVerified
<bool> 邮箱是否已验证CreateUserRequest.Phone
<string> 手机号CreateUserRequest.PhoneVerified
<bool> 手机号是否验证CreateUserRequest.Unionid
<string> 以社会化登录的用户该字段为用户在第三方社会化登录服务商中的唯一 IDCreateUserRequest.Openid
<string> 微信登录返回的 openidCreateUserRequest.Password
<string> 密码CreateUserRequest.RegisterSource
<string> 注册来源,可以多选CreateUserRequest.Username
<string> 用户名CreateUserRequest.Nickname
<string> 昵称CreateUserRequest.Photo
<string> 头像CreateUserRequest.Company
<string> 公司CreateUserRequest.Browser
<string> 浏览器CreateUserRequest.LoginsCount
<int> 登录次数,当你从原有用户系统迁移到 Authing 时可以设置该字段CreateUserRequest.LastLogin
<string> 上次登录时间, 符合 ISO8601 (opens new window) 格式的时间字符串。(如 "2017-06-07T14:34:08.700Z", "2017-06-07T14:34:08.700 or "2017-06-07T14:34:08+04:00")CreateUserRequest.LastIP
<string> 用户最近一次登录(或其他活动)的 IPCreateUserRequest.SignedUp
<string> 注册时间,符合 ISO8601 (opens new window) 格式的时间字符串。(如 "2017-06-07T14:34:08.700Z", "2017-06-07T14:34:08.700 or "2017-06-07T14:34:08+04:00")CreateUserRequest.Blocked
<bool> 账号是否被锁定CreateUserRequest.IsDeleted
<bool> 标记账号是否被删除CreateUserRequest.Device
<string> 设备CreateUserRequest.LastIP
<string> 最近登录的 IPCreateUserRequest.Name
<string> NameCreateUserRequest.GivenName
<string> Given NameCreateUserRequest.FamilyName
<string> Family NameCreateUserRequest.MiddleName
<string> Middle NameCreateUserRequest.Profile
<string> Profile UrlCreateUserRequest.PreferredUsername
<string> Preferred NameCreateUserRequest.Website
<string> 个人网站CreateUserRequest.Gender
<string> 性别, M(Man) 表示男性、F(Female) 表示女性、未知表示 U(Unknown)CreateUserRequest.Birthdate
<string> 生日CreateUserRequest.Zoneinfo
<string> 时区CreateUserRequest.Locale
<string> 语言CreateUserRequest.Address
<string> 地址CreateUserRequest.StreetAddress
<string> 街道地址CreateUserRequest.Locality
<string>CreateUserRequest.Region
<string> 地域CreateUserRequest.PostalCode
<string> 邮编CreateUserRequest.City
<string> 城市CreateUserRequest.Province
<string> 省份CreateUserRequest.Country
<string> 国家CreateUserRequest.ExternalId
<string> 内部员工 ID,此项在用户目录中为唯一
¶ 示例
phone := "15761403457222"
username := "xx"
pwd := "123456789"
var userInfo = &model.CreateUserInput{
Username: &username,
Phone: &phone,
Password: &pwd,
}
req := model.CreateUserRequest{
UserInfo: *userInfo,
}
resp, err := client.CreateUser(req)
¶ 返回值
¶ 示例数据
{
"id": "604a12a261a85949c8ad0259",
"arn": "arn:cn:authing:604a12a22d45ab775db56160:user:604a12a261a85949c8ad0259",
"userPoolId": "604a12a22d45ab775db56160",
"status": "Activated",
"username": "test",
"email": null,
"emailVerified": false,
"phone": null,
"phoneVerified": false,
"unionid": null,
"openid": null,
"nickname": null,
"registerSource": ["unknown"],
"photo": "https://files.authing.co/authing-console/default-user-avatar.png",
"password": null,
"oauth": null,
"token": null,
"tokenExpiredAt": null,
"loginsCount": 0,
"lastLogin": null,
"lastIP": null,
"signedUp": "2021-03-11T20:52:50+08:00",
"blocked": false,
"isDeleted": false,
"device": null,
"browser": null,
"company": null,
"name": null,
"givenName": null,
"familyName": null,
"middleName": null,
"profile": null,
"preferredUsername": null,
"website": null,
"gender": "U",
"birthdate": null,
"zoneinfo": null,
"locale": null,
"address": null,
"formatted": null,
"streetAddress": null,
"locality": null,
"region": null,
"postalCode": null,
"city": null,
"province": null,
"country": null,
"createdAt": "2021-03-11T20:52:50+08:00",
"updatedAt": "2021-03-11T20:52:50+08:00",
"externalId": null
}
¶ 修改用户资料
修改用户资料
//UpdateUser
//修改用户资料
func (c *Client) UpdateUser(id string, updateInfo model.UpdateUserInput) (*model.User, error)
¶ 参数
userId
<string> 用户 IDupdateInfo
<UpdateUserInput> 修改的用户资料UpdateUserInput.Email
<string> 邮箱UpdateUserInput.EmailVerified
<bool> 邮箱是否已验证UpdateUserInput.Phone
<string> 手机号UpdateUserInput.PhoneVerified
<bool> 手机号是否验证UpdateUserInput.Unionid
<string> 以社会化登录的用户该字段为用户在第三方社会化登录服务商中的唯一 IDUpdateUserInput.Openid
<string> 微信登录返回的 openidUpdateUserInput.Password
<string> 密码UpdateUserInput.RegisterSource
<string> 注册来源,可以多选UpdateUserInput.TokenExpiredAt
<string> token 过期时间,符合 ISO8601 (opens new window) 格式的时间字符串。(如 "2017-06-07T14:34:08.700Z", "2017-06-07T14:34:08.700 or "2017-06-07T14:34:08+04:00")。 将该字段设置为小于当前时间可以让用户的 token 失效UpdateUserInput.Username
<string> 用户名UpdateUserInput.Nickname
<string> 昵称UpdateUserInput.Photo
<string> 头像UpdateUserInput.Company
<string> 公司UpdateUserInput.Browser
<string> 浏览器UpdateUserInput.LoginsCount
<int> 登录次数,当你从原有用户系统迁移到 Authing 时可以设置该字段UpdateUserInput.LastLogin
<string> 上次登录时间, 符合 ISO8601 (opens new window) 格式的时间字符串。(如 "2017-06-07T14:34:08.700Z", "2017-06-07T14:34:08.700 or "2017-06-07T14:34:08+04:00")UpdateUserInput.LastIP
<string> 用户最近一次登录(或其他活动)的 IPUpdateUserInput.SignedUp
<string> 注册时间,符合 ISO8601 (opens new window) 格式的时间字符串。(如 "2017-06-07T14:34:08.700Z", "2017-06-07T14:34:08.700 or "2017-06-07T14:34:08+04:00")UpdateUserInput.Blocked
<bool> 账号是否被锁定UpdateUserInput.Device
<string> 设备UpdateUserInput.LastIP
<string> 最近登录的 IPUpdateUserInput.Name
<string> NameUpdateUserInput.GivenName
<string> Given NameUpdateUserInput.FamilyName
<string> Family NameUpdateUserInput.MiddleName
<string> Middle NameUpdateUserInput.Profile
<string> Profile UrlUpdateUserInput.PreferredUsername
<string> Preferred NameUpdateUserInput.Website
<string> 个人网站UpdateUserInput.Gender
<string> 性别, M(Man) 表示男性、F(Female) 表示女性、未知表示 U(Unknown)UpdateUserInput.Birthdate
<string> 生日UpdateUserInput.Zoneinfo
<string> 时区UpdateUserInput.Locale
<string> 语言UpdateUserInput.Address
<string> 地址UpdateUserInput.StreetAddress
<string> 街道地址UpdateUserInput.Locality
<string>UpdateUserInput.Region
<string> 地域UpdateUserInput.PostalCode
<string> 邮编UpdateUserInput.City
<string> 城市UpdateUserInput.Province
<string> 省份UpdateUserInput.Country
<string> 国家UpdateUserInput.ExternalId
<string> 用户外部 ID
¶ 示例
var userInfo = &model.UpdateUserInput{
Username: &username,
Phone: &phone,
}
resp, err := client.UpdateUser("616d4333b809f9f4768db847", *userInfo)
¶ 返回值
¶ 示例数据
{
"id": "604a12a261a85949c8ad0259",
"arn": "arn:cn:authing:604a12a22d45ab775db56160:user:604a12a261a85949c8ad0259",
"userPoolId": "604a12a22d45ab775db56160",
"status": "Activated",
"username": "test",
"email": null,
"emailVerified": false,
"phone": null,
"phoneVerified": false,
"unionid": null,
"openid": null,
"nickname": null,
"registerSource": ["unknown"],
"photo": "https://files.authing.co/authing-console/default-user-avatar.png",
"password": null,
"oauth": null,
"token": null,
"tokenExpiredAt": null,
"loginsCount": 0,
"lastLogin": null,
"lastIP": null,
"signedUp": "2021-03-11T20:52:50+08:00",
"blocked": false,
"isDeleted": false,
"device": null,
"browser": null,
"company": null,
"name": null,
"givenName": null,
"familyName": null,
"middleName": null,
"profile": null,
"preferredUsername": null,
"website": null,
"gender": "U",
"birthdate": null,
"zoneinfo": null,
"locale": null,
"address": null,
"formatted": null,
"streetAddress": null,
"locality": null,
"region": null,
"postalCode": null,
"city": null,
"province": null,
"country": null,
"createdAt": "2021-03-11T20:52:50+08:00",
"updatedAt": "2021-03-11T20:52:50+08:00",
"externalId": null
}
¶ 通过 ID 获取用户信息
通过用户 ID 获取用户详情,如果你想通过 token 获取用户详情,请使用 AuthenticationClient SDK
// Detail
// 获取用户详情
func (c *Client) Detail(userId string) (*model.User, error)
¶ 参数
userId
<string> 用户 ID
¶ 示例
resp, _ := client.Detail("60a6f9ad5bcccc51834950c5")
¶ 返回值
¶ 示例数据
{
"id": "604a12a261a85949c8ad0259",
"arn": "arn:cn:authing:604a12a22d45ab775db56160:user:604a12a261a85949c8ad0259",
"userPoolId": "604a12a22d45ab775db56160",
"status": "Activated",
"username": "test",
"email": null,
"emailVerified": false,
"phone": null,
"phoneVerified": false,
"identities": [],
"unionid": null,
"openid": null,
"nickname": null,
"registerSource": ["unknown"],
"photo": "https://files.authing.co/authing-console/default-user-avatar.png",
"password": null,
"oauth": null,
"token": null,
"tokenExpiredAt": null,
"loginsCount": 0,
"lastLogin": null,
"lastIP": null,
"signedUp": "2021-03-11T20:52:50+08:00",
"blocked": false,
"isDeleted": false,
"device": null,
"browser": null,
"company": null,
"name": null,
"givenName": null,
"familyName": null,
"middleName": null,
"profile": null,
"preferredUsername": null,
"website": null,
"gender": "U",
"birthdate": null,
"zoneinfo": null,
"locale": null,
"address": null,
"formatted": null,
"streetAddress": null,
"locality": null,
"region": null,
"postalCode": null,
"city": null,
"province": null,
"country": null,
"createdAt": "2021-03-11T20:52:50+08:00",
"updatedAt": "2021-03-11T20:52:50+08:00",
"externalId": null,
"customData": {
"school": "清华大学",
"age": 19
}
}
¶ 获取自定义数据
获取用户的自定义数据。你需要先在用户池定义用户自定义数据元信息
//GetUserUdfValue
//获取某个用户的所有自定义数据
func (c *Client) GetUserUdfValue(userId string) (*[]model.UserDefinedData, error)
¶ 参数
userId
<string> 用户 ID
¶ 示例
resp, err := client.GetUserUdfValue("616d41b7410a33da0cb70e65")
¶ 示例数据
{
"school": "华中科技大学",
"age": 20
}
¶ 批量获取自定义数据
批量获取多个用户的自定义数据。你需要先在用户池定义用户自定义数据元信息
// BatchGetUserUdfValue
// 批量获取多个用户的自定义数据
func (c *Client) BatchGetUserUdfValue(ids []string) (map[string][]model.UserDefinedData, error)
¶ 参数
ids
<[]string> 用户 ID 列表
¶ 示例
resp, err := client.BatchGetUserUdfValue([]string{"616d41b7410a33da0cb70e65"})
¶ 示例数据
{
"USER_ID1": {
"school": "华中科技大学",
"age": 20
},
"USER_ID2": {
"school": "北京大学",
"age": 21
}
}
¶ 设置自定义数据
设置用户的自定义数据。你需要先在用户池定义用户自定义数据元信息,且传入值的类型必须和定义的类型匹配
// SetUserUdfValue
// 设置某个用户的自定义数据
func (c *Client) SetUserUdfValue(id string, udv *model.KeyValuePair) (*[]model.UserDefinedData, error)
¶ 参数
id
<string> 用户 IDudv
<KeyValuePair>\ 自定义字段数据,类型为一个对象
¶ 示例
udv := model.KeyValuePair{
Key: "school",
Value: "1x1",
}
resp, err := client.SetUserUdfValue("616d41b7410a33da0cb70e65", &udv)
¶ 批量设置自定义数据
批量设置多个用户的自定义数据。你需要先在用户池定义用户自定义数据元信息,且传入值的类型必须和定义的类型匹配。如果设置失败,会抛出异常,你需要对异常进行捕捉
// BatchSetUserUdfValue
// 批量设置自定义数据
func (c *Client) BatchSetUserUdfValue(request *[]model.SetUdfValueBatchInput) (*model.CommonMessageAndCode, error)
¶ 参数
request
<SetUdfValueBatchInput>SetUdfValueBatchInput.TargetId
<string> 目标标识SetUdfValueBatchInput.Key
<string> 自定义 KeySetUdfValueBatchInput.Value
<string> 自定义 Value
¶ 示例
resp, err := client.SetUserUdfValue([]model.SetUdfValueBatchInput{{
TargetId:"id",
Key:"key",
Value:"val",
}})
¶ 删除自定义数据
删除自定义数据
// RemoveUserUdfValue
// 清除用户的自定义数据
func (c *Client) RemoveUserUdfValue(id, key string) (*[]model.UserDefinedData, error)
¶ 参数
id
<string> 用户 IDkey
<string> 自定义字段的 key
¶ 示例
resp, err := client.RemoveUserUdfValue("id","key")
¶ 删除用户
通过用户 ID 删除用户。删除用户会联级删除此用户管理的所有相关数据,无法恢复,请谨慎操作
//DeleteUser
//删除用户
func (c *Client) DeleteUser(id string) (*model.CommonMessageAndCode, error)
¶ 参数
id
<string> 用户 ID
¶ 示例
resp, err := client.DeleteUser("616d57e96dfa54908eda326f")
¶ 批量删除用户
批量删除用户,如果传入了不存在的用户 ID,会提示错误
//BatchDeleteUser
//批量删除用户
func (c *Client) BatchDeleteUser(ids []string) (*model.CommonMessageAndCode, error)
¶ 参数
ids
<[]string> 用户 ID 列表
¶ 示例
resp, err := client.BatchDeleteUser([]string{"616d430d58dbf82d1364453e"})
¶ 批量获取用户
通过 id、username、email、phone、email、externalId 批量获取用户详情。一次最多支持查询 80 个用户
//BatchGetUser
//通过 ID、username、email、phone、email、externalId 批量获取用户详情
func (c *Client) BatchGetUser(ids []string, queryField string, withCustomData bool) (*[]model.User, error)
¶ 参数
ids
<[]string> 需要查询的数据列表,如用户 ID 列表、手机号列表queryField
<string> 列表类型,可选值为 'id' ,'username' ,'phone' ,'email', 'externalId',默认为 'id'withCustomData
: <bool> 是否获取自定义数据,默认为 false;如果设置为 true,将会在customData
字段返回用户的所有自定义数据
{
"id": "604a12a261a85949c8ad0259",
"customData": {
"school": "清华大学",
"age": 19
}
}
¶ 示例
resp, err := client.BatchGetUser([]string{"xxq", "xx"}, "username", true)
¶ 示例数据
[
{
"id": "604a12a261a85949c8ad0259",
"arn": "arn:cn:authing:604a12a22d45ab775db56160:user:604a12a261a85949c8ad0259",
"userPoolId": "604a12a22d45ab775db56160",
"status": "Activated",
"username": "test",
"email": null,
"emailVerified": false,
"phone": null,
"phoneVerified": false,
"identities": [],
"unionid": null,
"openid": null,
"nickname": null,
"registerSource": ["unknown"],
"photo": "https://files.authing.co/authing-console/default-user-avatar.png",
"password": null,
"oauth": null,
"token": null,
"tokenExpiredAt": null,
"loginsCount": 0,
"lastLogin": null,
"lastIP": null,
"signedUp": "2021-03-11T20:52:50+08:00",
"blocked": false,
"isDeleted": false,
"device": null,
"browser": null,
"company": null,
"name": null,
"givenName": null,
"familyName": null,
"middleName": null,
"profile": null,
"preferredUsername": null,
"website": null,
"gender": "U",
"birthdate": null,
"zoneinfo": null,
"locale": null,
"address": null,
"formatted": null,
"streetAddress": null,
"locality": null,
"region": null,
"postalCode": null,
"city": null,
"province": null,
"country": null,
"createdAt": "2021-03-11T20:52:50+08:00",
"updatedAt": "2021-03-11T20:52:50+08:00",
"externalId": null
}
]
¶ 获取用户列表
获取用户池用户列表,该接口为分页接口
// GetUserList
// 获取用户列表
func (c *Client) GetUserList(request model.QueryListRequest) (*model.PaginatedUsers, error)
¶ 参数
request
<QueryListRequest>QueryListRequest.Page
<int> 页码数, 从 1 开始 默认值为 :1
QueryListRequest.Limit
<int> 每页包含的用户数 默认值为 :10
¶ 示例
custom := true
req := model.QueryListRequest{
Page: 1,
Limit: 10,
SortBy: enum.SortByCreatedAtAsc,
WithCustomData: &custom,
}
resp, _ := client.GetUserList(req)
¶ 示例数据
{
"totalCount": 1,
"list": [
{
"id": "604a12a261a85949c8ad0259",
"arn": "arn:cn:authing:604a12a22d45ab775db56160:user:604a12a261a85949c8ad0259",
"userPoolId": "604a12a22d45ab775db56160",
"status": "Activated",
"username": "test",
"email": null,
"emailVerified": false,
"phone": null,
"phoneVerified": false,
"unionid": null,
"openid": null,
"nickname": null,
"registerSource": ["unknown"],
"photo": "https://files.authing.co/authing-console/default-user-avatar.png",
"password": null,
"oauth": null,
"token": null,
"tokenExpiredAt": null,
"loginsCount": 0,
"lastLogin": null,
"lastIP": null,
"signedUp": "2021-03-11T20:52:50+08:00",
"blocked": false,
"isDeleted": false,
"device": null,
"browser": null,
"company": null,
"name": null,
"givenName": null,
"familyName": null,
"middleName": null,
"profile": null,
"preferredUsername": null,
"website": null,
"gender": "U",
"birthdate": null,
"zoneinfo": null,
"locale": null,
"address": null,
"formatted": null,
"streetAddress": null,
"locality": null,
"region": null,
"postalCode": null,
"city": null,
"province": null,
"country": null,
"createdAt": "2021-03-11T20:52:50+08:00",
"updatedAt": "2021-03-11T20:52:50+08:00",
"externalId": null
}
]
}
¶ 获取已归档用户列表
获取用户池已归档用户列表
//ListArchivedUsers
//获取已归档用户列表
func (c *Client) ListArchivedUsers(request model.CommonPageRequest) (*model.CommonPageUsersResponse, error)
¶ 参数
request
<CommonPageRequest>CommonPageRequest.Page
<int> 页码数, 从 1 开始 默认值为 :1
CommonPageRequest.Limit
<int> 每页包含的用户数 默认值为 :10
¶ 示例
resp, err := client.ListArchivedUsers(model.CommonPageRequest{
Page: 1,
Limit: 10,
})
¶ 示例数据
{
"totalCount": 20,
"list": [
{
// user info
},
{
// user info
}
]
}
¶ 检查用户是否存在
通过用户名、邮箱、手机号或者 ExternalId 检查用户是否存在
// CheckUserExists
// 检查用户是否存在
func (c *Client) CheckUserExists(request model.CheckUserExistsRequest) (bool, error)
¶ 参数
request
<CheckUserExistsRequest>CheckUserExistsRequest.Username
<string> 用户名,区分大小写CheckUserExistsRequest.Email
<string> 邮箱,邮箱不区分大小写CheckUserExistsRequest.Phone
<string> 手机号CheckUserExistsRequest.ExternalId
<string> External ID
¶ 示例
- 查询用户名
test
是否存在
phone := "15761403457"
req := model.CheckUserExistsRequest{
Email: nil,
Phone: &phone,
Username: nil,
ExternalId: nil,
}
resp, _ := client.CheckUserExists(req)
¶ 返回值
如果用户存在,返回 True 如果用户不存在,返回 False
¶ 查找用户
通过用户名、邮箱、手机号、External ID 精准查找用户
//FindUser
//查找用户
func (c *Client) FindUser(request *model.FindUserRequest) (*model.User, error)
¶ 参数
request
<FindUserRequest>FindUserRequest.Username
<string> 用户名,区分大小写FindUserRequest.Email
<string> 邮箱,邮箱不区分大小写FindUserRequest.Phone
<string> 手机号FindUserRequest.ExternalId
: External IDFindUserRequest.WithCustomData
: <bool> 是否获取自定义数据,默认为 false;如果设置为 true,将会在customData
字段返回用户的所有自定义数据
{
"id": "604a12a261a85949c8ad0259",
"customData": {
"school": "清华大学",
"age": 19
}
}
¶ 示例
- 通过用户名
test
查找
userName := "xxqq"
resp, err := client.FindUser(&model.FindUserRequest{
Username: &userName,
})
¶ 返回值
¶ 示例数据
{
"id": "604a12a261a85949c8ad0259",
"arn": "arn:cn:authing:604a12a22d45ab775db56160:user:604a12a261a85949c8ad0259",
"userPoolId": "604a12a22d45ab775db56160",
"status": "Activated",
"username": "test",
"email": null,
"emailVerified": false,
"phone": null,
"phoneVerified": false,
"unionid": null,
"openid": null,
"nickname": null,
"registerSource": ["unknown"],
"photo": "https://files.authing.co/authing-console/default-user-avatar.png",
"password": null,
"oauth": null,
"token": null,
"tokenExpiredAt": null,
"loginsCount": 0,
"lastLogin": null,
"lastIP": null,
"signedUp": "2021-03-11T20:52:50+08:00",
"blocked": false,
"isDeleted": false,
"device": null,
"browser": null,
"company": null,
"name": null,
"givenName": null,
"familyName": null,
"middleName": null,
"profile": null,
"preferredUsername": null,
"website": null,
"gender": "U",
"birthdate": null,
"zoneinfo": null,
"locale": null,
"address": null,
"formatted": null,
"streetAddress": null,
"locality": null,
"region": null,
"postalCode": null,
"city": null,
"province": null,
"country": null,
"createdAt": "2021-03-11T20:52:50+08:00",
"updatedAt": "2021-03-11T20:52:50+08:00",
"externalId": null,
"customData": {
"school": "清华大学",
"age": 19
}
}
¶ 搜索用户
根据关键字根据关键字模糊搜索用户,该接口为分页接口。模糊搜索用户
//SearchUser
//搜索用户
func (c *Client) SearchUser(request *model.SearchUserRequest) (*model.CommonPageUsersResponse, error)
¶ 参数
request
<SearchUserRequest>SearchUserRequest.Query
<string> 搜索内容SearchUserRequest.Page
<int> 默认值为 :1
SearchUserRequest.Limit
<int> 默认值为 :10
SearchUserRequest.DepartmentOpts
<string> 限制条件,用户所在部门DepartmentOpts.DepartmentId
<string> 部门 IDDepartmentOpts.IncludeChildrenDepartments
<bool> 是否搜索子节点
GroupOpts
<string>> 限制条件,用户所在分组GroupOpts.Code
<string> 分组 code
RoleOpts
<string>> 限制条件,用户所属角色RoleOpts.Namespace
<string> 角色命名空间RoleOpts.Code
<string> 角色 code
WithCustomData
: <bool> 是否获取自定义数据,默认为 false;如果设置为 true,将会在customData
字段返回用户的所有自定义数据
{
"id": "604a12a261a85949c8ad0259",
"customData": {
"school": "清华大学",
"age": 19
}
}
¶ 示例
- 模糊搜索用户
resp, err := client.SearchUser(&model.SearchUserRequest{
Query: "xxqq",
})
¶ 示例数据
{
"totalCount": 1,
"list": [
{
"id": "604a12a261a85949c8ad0259",
"arn": "arn:cn:authing:604a12a22d45ab775db56160:user:604a12a261a85949c8ad0259",
"userPoolId": "604a12a22d45ab775db56160",
"status": "Activated",
"username": "test",
"email": null,
"emailVerified": false,
"phone": null,
"phoneVerified": false,
"unionid": null,
"openid": null,
"nickname": null,
"registerSource": ["unknown"],
"photo": "https://files.authing.co/authing-console/default-user-avatar.png",
"password": null,
"oauth": null,
"token": null,
"tokenExpiredAt": null,
"loginsCount": 0,
"lastLogin": null,
"lastIP": null,
"signedUp": "2021-03-11T20:52:50+08:00",
"blocked": false,
"isDeleted": false,
"device": null,
"browser": null,
"company": null,
"name": null,
"givenName": null,
"familyName": null,
"middleName": null,
"profile": null,
"preferredUsername": null,
"website": null,
"gender": "U",
"birthdate": null,
"zoneinfo": null,
"locale": null,
"address": null,
"formatted": null,
"streetAddress": null,
"locality": null,
"region": null,
"postalCode": null,
"city": null,
"province": null,
"country": null,
"createdAt": "2021-03-11T20:52:50+08:00",
"updatedAt": "2021-03-11T20:52:50+08:00",
"externalId": null
}
]
}
¶ 强制下线一批用户
强制让一批用户在 Authing 下线
//KickUser
//强制一批用户下线
func (c *Client) KickUser(userIds []string) (*model.CommonMessageAndCode, error)
¶ 参数
userIds
<[]string> 用户 ID 数组
¶ 示例
resp, err := client.KickUser([]string{"5a597f35085a2000144a10ed"})
¶ 返回值
{ "code": 200, "message": "强制下线成功" }
¶ 获取用户分组列表
获取用户的分组列表
func (c *Client) GetUserGroupList(userId string) (*model.PaginatedGroups, error)
¶ 参数
userId
<string> 用户 ID
¶ 示例
resp, _ := client.GetUserGroupList("611a149db64310ca4764ab15")
¶ 示例数据
{
"totalCount": 1,
"list": [
{
"code": "test_group",
"name": "testGroup",
"description": null,
"createdAt": "2021-03-15T18:56:56+08:00",
"updatedAt": "2021-03-15T18:56:56+08:00"
}
]
}
¶ 加入分组
将用户加入分组
//AddUserToGroup
//将用户加入分组
func (c *Client) AddUserToGroup(userId, groupCode string) (*model.CommonMessageAndCode, error)
¶ 参数
userId
<string> 用户 IDgroupCode
<string> 分组 code
¶ 示例
resp, err := client.AddUserToGroup("616d41b7410a33da0cb70e65", "pngrn")
¶ 退出分组
将用户移出分组
//RemoveUserInGroup
//将用户退出分组
func (c *Client) RemoveUserInGroup(userId, groupCode string) (*model.CommonMessageAndCode, error)
¶ 参数
userId
<string> 用户 IDgroupCode
<string> 分组 code
¶ 示例
resp, err := client.RemoveUserInGroup("616d41b7410a33da0cb70e65", "pngrn")
¶ 获取用户角色列表
获取用户在某个权限分组下面的角色列表
//GetUserRoles
//获取用户角色列表
func (c *Client) GetUserRoles(request model.GetUserRolesRequest) (*struct {
TotalCount int `json:"totalCount"`
List []model.RoleModel `json:"list"`
}, error)
¶ 参数
request
<GetUserRolesRequest>GetUserRolesRequest.Id
<string> 用户 IDGetUserRolesRequest.Namespace
<string> 权限分组的 code,默认为默认权限分组
¶ 示例
request := &model.GetUserRolesRequest{
Id: "616d41b7410a33da0cb70e65",
}
resp, err := client.GetUserRoles(*request)
¶ 示例数据
{
"totalCount": 20,
"list": [
{
"namespace": "default",
/** 唯一标志 code */
"code": "example_code",
/** 资源描述符 arn */
"arn": "arn:xxxxxxx:xxxxxxx",
/** 角色描述 */
"description": "角色 1",
/** 是否为系统内建,系统内建的角色不能删除 */
"isSystem": false,
/** 创建时间 */
"createdAt": "2020-10-20T13:48:11.288Z",
/** 修改时间 */
"updatedAt": "2020-10-20T13:48:11.288Z",
/** 被授予此角色的用户列表 */
"users": "PaginatedUsers",
/** 父角色 */
"parent": null
}
]
}
¶ 添加角色
将用户加入角色
//AddUserToRoles
//将用户加入角色
func (c *Client) AddUserToRoles(request model.UserRoleOptRequest) (*model.CommonMessageAndCode, error)
¶ 参数
request
<UserRoleOptRequest>UserRoleOptRequest.UserIds
<[]string> 用户 IDUserRoleOptRequest.RoleCodes
<[]string> 角色 code 列表UserRoleOptRequest.Namespace
<string> 权限分组的 code,默认为默认权限分组
¶ 示例
request := &model.UserRoleOptRequest{
UserIds: []string{"616d41b7410a33da0cb70e65"},
RoleCodes: []string{"wwqhd"},
}
resp, err := client.AddUserToRoles(*request)
¶ 移除角色
将用户从角色中移除
//RemoveUserInRoles
//将用户从角色中移除
func (c *Client) RemoveUserInRoles(request model.UserRoleOptRequest) (*model.CommonMessageAndCode, error)
¶ 参数
request
<UserRoleOptRequest>UserRoleOptRequest.UserIds
<[]string> 用户 IDUserRoleOptRequest.RoleCodes
<[]string> 角色 code 列表UserRoleOptRequest.Namespace
<string> 权限分组的 code,默认为默认权限分组
¶ 示例
request := &model.UserRoleOptRequest{
UserIds: []string{"616d41b7410a33da0cb70e65"},
RoleCodes: []string{"wwqhd"},
}
resp, err := client.RemoveUserInRoles(*request)
¶ 判断用户是否有某个角色
判断用户是否有某个角色
// UserHasRole
// 判断用户是否有某个角色
func (c *Client) UserHasRole(userId, roleCode, namespace string) (bool, error)
¶ 参数
userId
<string> 用户 IDroleCode
<string> 角色 Codenamespace
<string> 权限分组的 code,详情请见使用权限分组管理权限资源
¶ 示例
resp, err := client.UserHasRole("616d41b7410a33da0cb70e65", "NewCode", "default")
¶ 示例数据
bool
¶ 刷新用户 Token
刷新用户 Token
//RefreshUserToken
//刷新用户 token
func (c *Client) RefreshUserToken(userId string) (*model.RefreshToken, error)
¶ 参数
userId
<string> 用户 ID
¶ 示例
resp, err := client.RefreshUserToken("616d41b7410a33da0cb70e65")
¶ 示例数据
{
"iat": 1632462741,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXo",
"exp": 1633758741
}
¶ 获取策略列表
获取策略列表
// ListUserPolicies
// 获取策略列表
func (c *Client) ListUserPolicies(request model.ListPoliciesOnIdRequest) (*model.ListPoliciesResponse, error)
¶ 参数
request
<ListPoliciesOnIdRequest>ListPoliciesOnIdRequest.Id
<string> 用户 IDListPoliciesOnIdRequest.Page
<int> 页码数, 从 1 开始 默认值为 :1
ListPoliciesOnIdRequest.Limit
<int> 每页包含的用户数 默认值为 :10
¶ 示例
req := model.ListPoliciesOnIdRequest{
Id: "616d41b7410a33da0cb70e65",
}
resp, err := client.ListUserPolicies(req)
¶ 示例数据
{
"totalCount": 1,
"list": [{
"targetType": "USER",
"code": "ewaoadwbbd",
"targetIdentifier": "614d68580d2abcd10f9e9a66"
}]
}
¶ 批量添加策略
批量添加策略
// AddUserPolicies
// 批量添加策略
func (c *Client) AddUserPolicies(userId string, policiesCode []string) (*model.CommonMessageAndCode, error)
¶ 参数
userId
<string> 用户 IDpoliciesCode
<[]string> 策略集合
¶ 示例
resp, err := client.AddUserPolicies("616d41b7410a33da0cb70e65", []string{"ehsncbahxr"})
¶ 示例数据
{
"message": "授权成功",
"code": 200
}
¶ 批量移除策略
批量移除策略
// RemoveUserPolicies
// 批量移除策略
func (c *Client) RemoveUserPolicies(userId string, policiesCode []string) (*model.CommonMessageAndCode, error)
¶ 参数
userId
<string> 用户 IDpoliciesCode
<[]string> 策略集合
¶ 示例
resp, err := client.RemoveUserPolicies("616d41b7410a33da0cb70e65", []string{"ehsncbahxr"})
¶ 示例数据
{
"message": "取消授权成功",
"code": 200
}
¶ 获取用户所在组织机构
获取用户所在组织机构
//ListUserOrg
//获取用户所在组织机构
func (c *Client) ListUserOrg(userId string) (*[][]model.OrgModel, error)
¶ 参数
userId
<string> 用户 ID
¶ 示例
resp, err := client.ListUserOrg("616d41b7410a33da0cb70e65")
¶ 获取用户所在部门
获取用户所在部门
// GetUserDepartments
// 获取用户所在部门
func (c *Client) GetUserDepartments(request model.GetUserDepartmentsRequest) (*model.PaginatedDepartments, error)
¶ 参数
request
<GetUserDepartmentsRequest>GetUserDepartmentsRequest.Id
<string> 用户 IDGetUserDepartmentsRequest.OrgId
<string> 机构 ID
¶ 示例
req := model.GetUserDepartmentsRequest{
Id: "60e400c1701ea5b98dae628d",
OrgId: nil,
}
resp, _ := client.GetUserDepartments(req)
¶ 示例数据
{
"departments": {
"totalCount": 0,
"list": []
}
}
¶ 发送首次登录验证邮件
发送首次登录验证邮件
// SendFirstLoginVerifyEmail
// 发送首次登录验证邮件
func (c *Client) SendFirstLoginVerifyEmail(userId, appId string) (*model.CommonMessageAndCode, error)
¶ 参数
userId
<string> 用户 IDappId
<string> 应用 ID
¶ 示例
resp, err := client.SendFirstLoginVerifyEmail("616d4333b809f9f4768db847", "6168f95e81d5e20f9cb72f22")
¶ 示例数据
{
"message": "发送成功",
"code": 200
}
¶ 用户退出登录
用户退出登录
//LogOut
//用户退出
func (c *Client) LogOut(userId string, appId *string) (*model.CommonMessageAndCode, error)
¶ 参数
userId
<string> 用户 IDappId
<string> 应用 ID
¶ 示例
resp, err := client.LogOut("5a597f35085a2000144a10ed", nil)
¶ 示例数据
{
"message": "退出成功",
"code": 200
}
¶ 检查用户登录状态
检查用户登录状态
//CheckLoginStatus
//检查用户登录状态
func (c *Client) CheckLoginStatus(userId string, appId, deviceId *string) (*model.CommonMessageAndCode, error)
¶ 参数
userId
<string> 用户 IDappId
<string> 应用 IDdeviceId
<string> 设备 ID
¶ 示例
resp, err := client.CheckLoginStatus("5a597f35085a2000144a10ed", nil, nil)
¶ 获取用户所在的租户
获取用户所在的租户
// GetUserTenants
// 获取用户所在租户
func (c *Client) GetUserTenants(userId string) (*model.GetUserTenantsResponse, error)
¶ 参数
userId
<string> 用户 ID
¶ 示例
resp, err := client.GetUserTenants("61b85b945468e9865acae737")
本文是否有解决您的问题?
如果遇到其他问题,你可以在 authing-chat/community 联系我们。