示例#1
0
        protected override void SaveSharePointContext(SharePointContext spContext, HttpContext httpContext)
        {
            SharePointAcsContext spAcsContext = spContext as SharePointAcsContext;

            //creates a cookie to store the SPCacheKey
            if (spAcsContext != null)
            {
                //The following code generates a cookie in the response with the SPCacheKey as a value
                var options = new CookieOptions()
                {
                    HttpOnly = true, Secure = true
                };
                httpContext.Response.Cookies.Append(SPCacheKeyKey, spAcsContext.CacheKey, options);
            }
            string output = JsonConvert.SerializeObject(spAcsContext);

            byte[] bytes = new byte[output.Length * sizeof(char)];
            System.Buffer.BlockCopy(output.ToCharArray(), 0, bytes, 0, bytes.Length);
            httpContext.Session.Set(SPContextKey, bytes);
        }
示例#2
0
        protected override bool ValidateSharePointContext(SharePointContext spContext, HttpContext httpContext)
        {
            SharePointAcsContext spAcsContext = spContext as SharePointAcsContext;

            //Checks for the SPCacheKey cookie and gets the value
            if (spAcsContext != null)
            {
                Uri spHostUrl = SharePointContext.GetUriFromQueryStringParameter
                                    (httpContext.Request, SharePointContext.SPHostUrlKey);

                string contextToken = TokenHandler.GetContextTokenFromRequest(httpContext.Request);
                //read the cookie value
                HttpCookie spCacheKeyCookie = new HttpCookie(SPCacheKeyKey, httpContext.Request.Cookies[SPCacheKeyKey]);
                string     spCacheKey       = spCacheKeyCookie != null ? spCacheKeyCookie.Value : null;

                return(spHostUrl == spAcsContext.SPHostUrl &&
                       !string.IsNullOrEmpty(spAcsContext.CacheKey) &&
                       spCacheKey == spAcsContext.CacheKey &&
                       !string.IsNullOrEmpty(spAcsContext.ContextToken) &&
                       (string.IsNullOrEmpty(contextToken) || contextToken == spAcsContext.ContextToken));
            }

            return(false);
        }