我正在使用 MSAL,并且有一个用户收到以下错误:
{
"error":{
"code":"ResourceNotFound",
"message":"Resource could not be discovered.",
"innerError":{
"request-id":"99b44a33-e5cd-4b69-9730-32d72e1f4ebf",
"date":"2016-12-11T03:51:37"
}
}
}
该代码是默认的 MSAL 演示代码:
public async Task<ActionResult> ReadMail()
{
try
{
string signedInUserID = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
ConfidentialClientApplication cca = new ConfidentialClientApplication(clientId, null,
new ClientCredential(appKey), new MSALSessionCache(signedInUserID, this.HttpContext));
string[] scopes = { "Mail.Read" };
AuthenticationResult result = await cca.AcquireTokenSilentAsync(scopes);
HttpClient hc = new HttpClient();
hc.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", result.Token);
HttpResponseMessage hrm = await hc.GetAsync("https://graph.microsoft.com/v1.0/me/messages");
string rez = await hrm.Content.ReadAsStringAsync();
ViewBag.Message = rez;
return View();
}
catch (MsalSilentTokenAcquisitionException)
{
ViewBag.Relogin = "true";
return View();
}
catch (Exception eee)
{
ViewBag.Error = "An error has occurred. Details: " + eee.Message;
return View();
}
}
原来集成是这样的:
- 这是一个混合交换系统
- 某些邮箱位于 Office 365 上。
- 一些邮箱位于本地。
- 其他邮箱位于第 3 方邮件系统(Intermedia)上(目录通过自定义脚本同步到 AD Connect)
问题
我应该如何针对上述情况进行防御性编码?(或类似的混合情况)?