Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. {
  2. "error":{
  3. "code":"ResourceNotFound",
  4. "message":"Resource could not be discovered.",
  5. "innerError":{
  6. "request-id":"99b44a33-e5cd-4b69-9730-32d72e1f4ebf",
  7. "date":"2016-12-11T03:51:37"
  8. }
  9. }
  10. }
  11.  
  12. public async Task<ActionResult> ReadMail()
  13. {
  14. try
  15. {
  16. string signedInUserID = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
  17. ConfidentialClientApplication cca = new ConfidentialClientApplication(clientId, null,
  18. new ClientCredential(appKey), new MSALSessionCache(signedInUserID, this.HttpContext));
  19. string[] scopes = { "Mail.Read" };
  20. AuthenticationResult result = await cca.AcquireTokenSilentAsync(scopes);
  21.  
  22. HttpClient hc = new HttpClient();
  23. hc.DefaultRequestHeaders.Authorization =
  24. new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", result.Token);
  25. HttpResponseMessage hrm = await hc.GetAsync("https://graph.microsoft.com/v1.0/me/messages");
  26. string rez = await hrm.Content.ReadAsStringAsync();
  27. ViewBag.Message = rez;
  28.  
  29. return View();
  30. }
  31. catch (MsalSilentTokenAcquisitionException)
  32. {
  33. ViewBag.Relogin = "true";
  34. return View();
  35. }
  36. catch (Exception eee)
  37. {
  38. ViewBag.Error = "An error has occurred. Details: " + eee.Message;
  39. return View();
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement