protected override SharePointContext CreateSharePointContext(Uri spHostUrl, Uri spAppWebUrl, string spLanguage, string spClientTag, string spProductNumber, HttpRequest httpRequest) { string contextTokenString = TokenHandler.GetContextTokenFromRequest(httpRequest); if (string.IsNullOrEmpty(contextTokenString)) { return(null); } SharePointContextToken contextToken = null; try { contextToken = TokenHandler.ReadAndValidateContextToken(contextTokenString, httpRequest.Host.Value); } //catch (WebException) //{ // return null; //} catch (AudienceUriValidationFailedException) { return(null); } return(new SharePointAcsContext(spHostUrl, spAppWebUrl, spLanguage, spClientTag, spProductNumber, contextTokenString, contextToken, Configuration)); }
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 var cookieCollection = httpContext.Request.Cookies; if (!cookieCollection.ContainsKey(SPCacheKeyKey)) { return(false); } var spCacheKeyCookieValue = httpContext.Request.Cookies[SPCacheKeyKey]; string spCacheKey = spCacheKeyCookieValue != null ? spCacheKeyCookieValue : null; //return spHostUrl == spAcsContext.SPHostUrl && (taken out) return (!string.IsNullOrEmpty(spAcsContext.CacheKey) && spCacheKey == spAcsContext.CacheKey && !string.IsNullOrEmpty(spAcsContext.ContextToken) && (string.IsNullOrEmpty(contextToken) || contextToken == spAcsContext.ContextToken)); } return(false); }
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); }