I am working with MSAL and have a user who received the following error:
{
"error":{
"code":"ResourceNotFound",
"message":"Resource could not be discovered.",
"innerError":{
"request-id":"99b44a33-e5cd-4b69-9730-32d72e1f4ebf",
"date":"2016-12-11T03:51:37"
}
}
}
The code is the default MSAL demo code:
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();
}
}
It turns out that the integration is like this:
- It's a Hybrid Exchange system
- Some mailboxes are located on Office 365.
- Some mailboxes are located on premise.
- Other mailboxes are on a 3rd party mail system (Intermedia) (the directory syncs to AD Connect via a custom script)
Question
How should I defensively code for the above situation? (or similar hybrid situations)?