【发布时间】:2024-01-21 09:51:01
【问题描述】:
所以我正在使用与 Azure AD 绑定的默认 MVC 5 开箱即用模板。上次运行时它运行良好,但现在我无法运行用户配置文件。以前运行良好的东西。我测试了我知道可以工作的第二个项目,现在收到了同样的错误。如果您查看默认模板中的代码,它看起来像这样。
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 吗???开始觉得它只是服务的开发人员和我自己使用这个.....
标签: azure https active-directory single-sign-on adfs