public async Task <ActionResult> Calendar() { if (Request.IsAuthenticated) { APIManager api = new APIManager(Session["USER"].ToString()); string token = await api.GetAccessToken(HttpContext); if (string.IsNullOrEmpty(token)) { // If there's no token in the session, redirect to Home return(Redirect("/")); } GraphServiceClient client = new GraphServiceClient( new DelegateAuthenticationProvider( (requestMessage) => { requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); return(Task.FromResult(0)); })); try { var eventResults = await client.Me.Events.Request() .OrderBy("start/dateTime DESC") .Select("subject,start,end") .Top(10) .GetAsync(); return(View(eventResults.CurrentPage)); } catch (ServiceException ex) { return(RedirectToAction("Error", "Home", new { message = "ERROR retrieving events", debug = ex.Message })); } } else { return(RedirectToAction("SignOut", "Home", null)); } }