我正在尝试使用 Google 目录服务更新用户,但出现错误:“400 密码无效”。这是我使用的代码:
var certificate = new X509Certificate2(certificatePath, "notasecret",
X509KeyStorageFlags.Exportable);
var sai = new ServiceAccountCredential.Initializer(clientId)
{
Scopes = new[]
{
DirectoryService.Scope.AdminDirectoryUser,
DirectoryService.Scope.AdminDirectoryDomain
}
}.FromCertificate(certificate);
sai.User = "admin@domain.com";
ServiceAccountCredential credential = new ServiceAccountCredential(sai);
var directoryService = new DirectoryService(new BaseClientService.Initializer
{
ApplicationName = "Admin",
HttpClientInitializer = credential
});
User user = directoryService.Users.Get("someuser@domain.com").Execute();
user.Password = "SomeP@ssword1234";
directoryService.Users.Update(user, "someuser@2contact.com").Execute(); // Error 400 Invalid password
最后一行抛出错误。获取现有用户的方法是:
var listRequest = _directoryService.Users.List();
listRequest.Domain = "domain.com";
listRequest.MaxResults = 500;
var results = listRequest.Execute(); // Works fine!
我究竟做错了什么?