Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "error":{
- "code":"ResourceNotFound",
- "message":"Resource could not be discovered.",
- "innerError":{
- "request-id":"99b44a33-e5cd-4b69-9730-32d72e1f4ebf",
- "date":"2016-12-11T03:51:37"
- }
- }
- }
- 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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement