現在、国際的な雲の中にあるものと、ドイツのものの中にあるAzureの2つの同様のWebアプリケーションがあります。 Graph-APIを使用して、ユーザーの初期パスワードを変更しています。これは国際版では機能しますが、ドイツ語版でも同じように試してみると失敗します。下記のドイツのアプリのコードを示すメソッドを参照してください。国際版には明らかに他のID、キー、URLがありますが、同じロジックを使用しています。Azure Germany:変更を呼び出すパスワードが機能しない
コードをデバッグすると、トークンが取得され、そのトークンをPOSTメソッドとして使用できます。これは、(client.PostAsyncを呼び出した後)レスポンスです:
ID = 42、ステータス= RanToCompletion、メソッド= "{ヌル}"、=「結果のStatusCode:500、 のreasonPhrase: '内部サーバーエラー'バージョン:1.1、 内容:System.Net.Http.StreamContent、 ヘッダ:\ rを\ nは{\がR \ nを
OCP-AAD-診断サーバ名:5gghBUs/J/tLLA4x7srNaYCSuNTD7zpqDaqBOfa330o = \ rを\ nは
要求ID:2258910e-3b51-47a7-bd81-90eb46a31cb0の\ r \ n
クライアント要求ID:{myClientId} \ R \ nは
}」(...)
すべてのID、キー、およびURLを10倍にチェックしました。私は何が欠けていますか? (クライアントID、ユーザー名などは匿名です)
private async static Task<string> ChangePasswordDE()
{
try
{
string clientId = "{myClientID }";
string authority = "https://login.microsoftonline.de/{TenantID}/";
string userName = "[email protected]";
string oldPassword = "thisIsOld1234";
string newPassword = "thisIsNew5678";
var ctx = new AuthenticationContext(authority, false);
var pwCred = new UserPasswordCredential(userName, oldPassword);
var result = ctx.AcquireTokenAsync("https://graph.cloudapi.de/", clientId, pwCred).Result;
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", result.AccessToken);
var requestUri = "https://graph.cloudapi.de/me/changePassword?api-version=1.6";
object newPwd = new { currentPassword = oldPassword, newPassword = newPassword };
var body = JsonConvert.SerializeObject(newPwd);
Uri uri = new Uri(requestUri);
StringContent content = new StringContent(body, System.Text.Encoding.UTF8, "application/json");
Console.WriteLine("Post Async");
var response = client.PostAsync(uri, content).Result;
ctx.TokenCache.Clear();
if (response.IsSuccessStatusCode)
{
Console.WriteLine("Worked!");
return "OK";
}
else
{
Console.WriteLine(response.ReasonPhrase);
Console.WriteLine("Did not work!");
return "Error";
}
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
return ex.InnerException.ToString();
}
}