2017-02-24 91 views
0

我們目前在Azure上託管兩個類似的webapps,一個位於國際雲端,一個位於德國境內。我們正在使用Graph-API來更改用戶的初始密碼。這適用於國際版本,但在嘗試使用德國版本時會失敗。請參閱下面的方法,其中顯示了德國應用程序的代碼。國際版顯然具有其他ID,鍵和URL,但使用相同的邏輯。Azure Germany:撥打changePassword不起作用

調試代碼,我確實得到了一個令牌,並且我可以將該令牌用於POST方法。這是響應(主叫client.PostAsync後):

編號= 42,狀態= RanToCompletion,方法= 「{NULL}」,結果=「的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十倍。我錯過了什麼? (客戶端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(); 
     } 

    } 

回答

0

我們一直在與微軟聯繫。 Azure德國確實實施了Graph API,但截至2017年3月1日,並非所有功能都已完全正常工作。以上述方式使用的ChangePassword就是其中之一。