public override async System.Threading.Tasks.Task <System.Net.Http.HttpResponseMessage> ProcessBatchAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
        {
            System.Net.Http.HttpResponseMessage response = await base.ProcessBatchAsync(request, cancellationToken);

            OAuthController.RemoveFromCache("cookieToken");
            OAuthController.RemoveFromCache("formToken");
            return(response);
        }
        public ActionResult Index()
        {
            //The application is configured to authenticate against O365
            //Then another round trip is made to get an access token for SharePoint
            string resource         = ConfigurationManager.AppSettings["ida:Resource"];
            string redirectUri      = this.Request.Url.GetLeftPart(UriPartial.Authority).ToString() + "/Home/SPA";
            string authorizationUrl = OAuthController.GetAuthorizationUrl(resource, new Uri(redirectUri));

            return(new RedirectResult(authorizationUrl));
        }
        public override void ValidateRequest(System.Net.Http.HttpRequestMessage request)
        {
            string cookieToken = string.Empty;
            string formToken   = string.Empty;

            IEnumerable <string> tokenHeaders;

            if (request.Headers.TryGetValues("RequestVerificationToken", out tokenHeaders))
            {
                string[] tokens = tokenHeaders.First().Split(':');
                if (tokens.Length == 2)
                {
                    cookieToken = tokens[0].Trim();
                    formToken   = tokens[1].Trim();
                    OAuthController.SaveInCache("cookieToken", cookieToken);
                    OAuthController.SaveInCache("formToken", formToken);
                }
            }

            AntiForgery.Validate(cookieToken, formToken);
            base.ValidateRequest(request);
        }