因此,我正在使用與Azure AD關聯的默認MVC 5開箱模板。上次運行時它運行良好,但現在我無法獲取用戶配置文件的運行。以前工作得很好的東西。我測試了一個我知道要工作的第二個項目,現在我收到了同樣的錯誤。如果您查看默認模板中的代碼,它看起來像這樣。UserProfile()上的Azure Active Directory圖形API HTTP 400錯誤請求;
public async Task<ActionResult> UserProfile()
{
string tenantId = ClaimsPrincipal.Current.FindFirst(TenantIdClaimType).Value;
// Get a token for calling the Windows Azure Active Directory Graph
AuthenticationContext authContext = new AuthenticationContext(String.Format(CultureInfo.InvariantCulture, LoginUrl, tenantId));
ClientCredential credential = new ClientCredential(AppPrincipalId, AppKey);
AuthenticationResult assertionCredential = authContext.AcquireToken(GraphUrl, credential);
string authHeader = assertionCredential.CreateAuthorizationHeader();
string requestUrl = String.Format(
CultureInfo.InvariantCulture,
GraphUserUrl,
HttpUtility.UrlEncode(tenantId),
HttpUtility.UrlEncode(User.Identity.Name));
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUrl);
request.Headers.TryAddWithoutValidation("Authorization", authHeader);
HttpResponseMessage response = await client.SendAsync(request);
string responseString = await response.Content.ReadAsStringAsync();
UserProfile profile = JsonConvert.DeserializeObject<UserProfile>(responseString);
return View(profile);
}
它是專門未能在這條線:
AuthenticationResult assertionCredential = authContext.AcquireToken(GraphUrl, credential);
我檢查我的Azure的門戶網站,所有端點都是正確的。這方面沒有任何改變。堆棧跟蹤沒有給我任何意義。除了網頁上的HTTP 400錯誤,以及Chrome開發工具內部,我看到一個HTTP 500服務器錯誤。除此之外,一切似乎都在起作用。不知道過去4天內Azure是否發生過更改。但是我無法在這個問題上找到任何信息。
我正在使用VS 2013.在這個版本上還沒有很多文檔,因爲AD Graph API似乎設置的不同於它們在示例中顯示的內容。任何有關如何進一步調試的幫助將不勝感激。
有沒有其他人使用過這個版本的API?開始感覺它只是服務的開發者,而我自己則使用這個..... –