コード例 #1
0
        /// <summary>
        /// Gets the facebook signed request from the http request.
        /// </summary>
        /// <param name="appSecret">
        /// The app Secret.
        /// </param>
        /// <param name="httpContext">
        /// The http context.
        /// </param>
        /// <returns>
        /// Returns the signed request if found otherwise null.
        /// </returns>
        internal static FacebookSignedRequest GetSignedRequest(string appSecret, HttpContextBase httpContext)
        {
            Contract.Requires(httpContext != null);
            Contract.Requires(httpContext.Request != null);
            Contract.Requires(httpContext.Request.Params != null);

            var items       = httpContext.Items;
            var httpRequest = httpContext.Request;
            FacebookSignedRequest signedRequest;

            if (items[HttpContextKey] == null)
            {
                signedRequest         = (httpRequest.Params.AllKeys.Contains(SignedRequestKey) && !string.IsNullOrEmpty(httpRequest.Params[SignedRequestKey])) ? FacebookSignedRequest.Parse(appSecret, httpRequest.Params[SignedRequestKey]) : null;
                items[HttpContextKey] = signedRequest;
            }
            else
            {
                signedRequest = items[HttpContextKey] as FacebookSignedRequest;
            }
            return(signedRequest);
        }
コード例 #2
0
        /// <summary>
        /// Gets the facebook signed request from the http request.
        /// </summary>
        /// <param name="appSecret">
        /// The app Secret.
        /// </param>
        /// <param name="httpContext">
        /// The http context.
        /// </param>
        /// <returns>
        /// Returns the signed request if found otherwise null.
        /// </returns>
        internal static FacebookSignedRequest GetSignedRequest(string appId, string appSecret, HttpContextBase httpContext)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }

            var items       = httpContext.Items;
            var httpRequest = httpContext.Request;
            FacebookSignedRequest signedRequest;

            if (items[HttpContextKey] == null)
            {
                signedRequest = httpRequest.Params.AllKeys.Contains(SignedRequestKey) && !string.IsNullOrEmpty(httpRequest.Params[SignedRequestKey]) ? FacebookSignedRequest.Parse(appSecret, httpRequest.Params[SignedRequestKey]) : null;
                if (signedRequest == null && !string.IsNullOrEmpty(appId))
                {
                    var signedRequestCookieValue = GetSignedRequestCookieValue(appId, httpRequest);
                    if (!string.IsNullOrEmpty(signedRequestCookieValue))
                    {
                        signedRequest = Parse(appSecret, signedRequestCookieValue);
                    }
                }

                items[HttpContextKey] = signedRequest;
            }
            else
            {
                signedRequest = items[HttpContextKey] as FacebookSignedRequest;
            }
            return(signedRequest);
        }