class AuthingRuby::UsersManagementClient

Public Class Methods

new(options = {}, graphqlClient = nil, httpClient = nil, tokenProvider = nil, publicKeyManager = nil) click to toggle source
# File lib/authing_ruby/management/UsersManagementClient.rb, line 7
def initialize(options = {}, graphqlClient = nil, httpClient = nil, tokenProvider = nil, publicKeyManager = nil)
  @options = options
  @graphqlClient = graphqlClient
  @httpClient = httpClient
  @tokenProvider = tokenProvider
  @publicKeyManager = publicKeyManager
end

Public Instance Methods

batch() click to toggle source

TODO 批量获取用户

# File lib/authing_ruby/management/UsersManagementClient.rb, line 113
def batch
end
create(userInfo = {}, options = {}) click to toggle source

创建用户

# File lib/authing_ruby/management/UsersManagementClient.rb, line 16
def create(userInfo = {}, options = {})
  keepPassword = options.fetch(:keepPassword, false)
  password = userInfo.fetch(:password, nil)
  # 先对密码进行处理
  if password
    publicKey = @publicKeyManager.getPublicKey()
    encryptedPassword = AuthingRuby::Utils.encrypt(password, publicKey)
    userInfo[:password] = encryptedPassword
  end

  # 然后再发请求
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  variables = {
    "userInfo": userInfo,
    "keepPassword": keepPassword,
  }
  hash = graphqlAPI.createUser(@graphqlClient, @tokenProvider, variables)
  user = hash.dig("data", "createUser")
  return user if user
  return hash
end
delete(user_id) click to toggle source

删除用户

# File lib/authing_ruby/management/UsersManagementClient.rb, line 73
def delete(user_id)
  variables = {
    "id": user_id,
  }
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  hash = graphqlAPI.deleteUser(@graphqlClient, @tokenProvider, variables)
  # {"data":{"deleteUser":{"message":"删除成功!","code":200}}}
  data = hash.dig("data", "deleteUser")
  return data if data
  return hash
end
deleteMany(user_ids = []) click to toggle source

批量删除用户

# File lib/authing_ruby/management/UsersManagementClient.rb, line 86
def deleteMany(user_ids = [])
  variables = {
    "ids": user_ids,
  }
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  hash = graphqlAPI.deleteUsers(@graphqlClient, @tokenProvider, variables)
  # {"data":{"deleteUsers":{"message":"删除成功!","code":200}}}
  data = hash.dig("data", "deleteUsers")
  return data if data
  return hash
end
detail(user_id) click to toggle source

通过 ID 获取用户信息

# File lib/authing_ruby/management/UsersManagementClient.rb, line 61
def detail(user_id)
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  variables = {
    "id": user_id,
  }
  hash = graphqlAPI.user(@graphqlClient, @tokenProvider, variables)
  user = hash.dig("data", "user")
  return user if user
  return hash
end
exists(options = {}) click to toggle source

检查用户是否存在

# File lib/authing_ruby/management/UsersManagementClient.rb, line 117
def exists(options = {})
  username = options.fetch(:username, nil)
  email = options.fetch(:email, nil)
  phone = options.fetch(:phone, nil)
  if username == nil && email == nil && phone == nil
    throw "缺少参数, 请至少传入一个选项: username, email, phone"
  end

  variables = {
    "username": username,
    "email": email,
    "phone": phone,
  }
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  hash = graphqlAPI.isUserExists(@graphqlClient, @tokenProvider, variables)
  data = hash.dig("data", "isUserExists")
  return data if data
  return hash
end
find(options = {}) click to toggle source

查找用户

# File lib/authing_ruby/management/UsersManagementClient.rb, line 138
def find(options = {})
  username = options.fetch(:username, nil)
  email = options.fetch(:email, nil)
  phone = options.fetch(:phone, nil)
  externalId = options.fetch(:externalId, nil)
  if username == nil && email == nil && phone == nil && externalId == nil
    throw "缺少参数, 请至少传入一个选项: username, email, phone, externalId"
  end

  variables = {
    "username": username,
    "email": email,
    "phone": phone,
    "externalId": externalId,
  }
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  hash = graphqlAPI.findUser(@graphqlClient, @tokenProvider, variables)
  data = hash.dig("data", "findUser")
  return data if data
  return hash
end
list(page = 1, limit = 10) click to toggle source

获取用户列表

# File lib/authing_ruby/management/UsersManagementClient.rb, line 99
def list(page = 1, limit = 10)
  variables = {
    "page": page,
    "limit": limit,
  }
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  hash = graphqlAPI.users(@graphqlClient, @tokenProvider, variables)
  data = hash.dig("data", "users")
  return data if data
  return hash
end
listRoles(user_id) click to toggle source
refreshToken() click to toggle source

TODO

# File lib/authing_ruby/management/UsersManagementClient.rb, line 165
def refreshToken
end
update(id, updates = {}) click to toggle source

修改用户资料

# File lib/authing_ruby/management/UsersManagementClient.rb, line 39
def update(id, updates = {})
  # 预处理密码(如果有的话)
  password = updates.fetch(:password, nil)
  if password
    publicKey = @publicKeyManager.getPublicKey()
    encryptedPassword = AuthingRuby::Utils.encrypt(password, publicKey)
    updates[:password] = encryptedPassword
  end

  # 然后再发请求
  graphqlAPI = AuthingRuby::GraphQLAPI.new
  variables = {
    "id": id,
    "input": updates
  }
  hash = graphqlAPI.updateUser(@graphqlClient, @tokenProvider, variables)
  user = hash.dig("data", "updateUser")
  return user if user
  return hash
end