2017-06-09 9 views
0

Googleディレクトリサービスを使用してユーザーを更新しようとしていますが、「400パスワードが無効です」というエラーが表示されます。私が使用しているコードは次のとおりです。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 = "[email protected]"; 

ServiceAccountCredential credential = new ServiceAccountCredential(sai); 

var directoryService = new DirectoryService(new BaseClientService.Initializer 
              { 
               ApplicationName = "Admin", 
               HttpClientInitializer = credential 
              }); 

User user = directoryService.Users.Get("[email protected]").Execute(); 
user.Password = "[email protected]"; 
directoryService.Users.Update(user, "[email protected]").Execute(); // Error 400 Invalid password 

最後の行でエラーが発生します。既存のユーザーを取得 を経由して動作します:

var listRequest = _directoryService.Users.List(); 
listRequest.Domain = "domain.com"; 
listRequest.MaxResults = 500; 
var results = listRequest.Execute(); // Works fine! 

は私が間違って何をしているのですか?

+1

あなたの 'User'オブジェクトに空でない' HashFunction'がありますか?ドキュメントからの注意: "hashFunctionが指定されている場合、パスワードは有効なハッシュキーでなければなりません。" –

+0

私はドキュメンテーションでそれを見落としました。私は次の月曜日に見ていきます。 –

+0

ハッシュ関数を指定しませんでしたが、何らかの理由でそれが機能しませんでした。今SHA1を使用して、それは正常に動作します。 –

答えて

0

テストするために特殊文字を使わずに試しましたか?おそらく、エンコーディングに関するいくつかの問題があります。 Googleは最低限の文字数しか要求しません。

一方、アップロードする前にAPIをハッシュで暗号化することをお勧めします。

The user's password value is required when creating a user account. It is optional when updating a user and should only be provided if the user is updating their account password. A password can contain any combination of ASCII characters. A minimum of 8 characters is required. The maximum length is 100 characters. We recommend sending the password property value as a base 16 bit, hexidecimal-encoded hash value. If a hashFunction is specified, the password must be a valid hash key.

The password value is never returned in the API's response body.

+1

SHA1ハッシュ関数を使用して、それは動作します、ありがとう。 –

関連する問題