コード例 #1
0
 public override void ProcessSubscription(FacebookSubscriptionContext context, object result)
 {
     Contract.Requires(context != null);
     Contract.Requires(context.HttpContext.Request != null);
     Contract.Requires(context.HttpContext.Request.Params != null);
     Contract.Requires(context.HttpContext.Response != null);
 }
コード例 #2
0
 /// <summary>
 /// Handles unauthorized requests.
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 public virtual void HandleUnauthorizedRequest(FacebookSubscriptionContext context)
 {
     Contract.Requires(context != null);
     Contract.Requires(context.HttpContext != null);
     Contract.Requires(context.HttpContext.Response != null);
     context.HttpContext.Response.StatusCode = 401;
 }
コード例 #3
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests. </param>
        public void ProcessRequest(HttpContext context)
        {
            var subContext = new FacebookSubscriptionContext
            {
                HttpContext         = new HttpContextWrapper(context),
                FacebookApplication = FacebookApplication.Current,
            };

            OnVerifying(subContext);
            VerifyCore(subContext);
        }
コード例 #4
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContextWrapper"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests. </param>
        public virtual void VerifyCore(FacebookSubscriptionContext context)
        {
            Contract.Requires(context != null);
            Contract.Requires(context.HttpContext != null);
            Contract.Requires(context.HttpContext.Request != null);
            Contract.Requires(context.HttpContext.Request.Params != null);
            Contract.Requires(context.HttpContext.Response != null);
            Contract.Requires(context.FacebookApplication != null);

            context.HttpContext.Response.ContentType = "text/plain";
            var request = context.HttpContext.Request;

            string errorMessage;

            switch (request.HttpMethod)
            {
            case "GET":
                if (!string.IsNullOrEmpty(context.VerificationToken) &&
                    FacebookSubscriptionVerifier.VerifyGetSubscription(request, context.VerificationToken, out errorMessage))
                {
                    context.HttpContext.Response.Write(request.Params["hub.challenge"]);
                }
                else
                {
                    HandleUnauthorizedRequest(context);
                }

                break;

            case "POST":
            {
                var reader     = new System.IO.StreamReader(request.InputStream);
                var jsonString = reader.ReadToEnd();

                var secret = context.FacebookApplication.AppSecret;
                if (!string.IsNullOrEmpty(secret) &&
                    FacebookSubscriptionVerifier.VerifyPostSubscription(request, secret, jsonString, out errorMessage))
                {
                    // might need to put try catch when desterilizing object
                    var jsonObject = JsonSerializer.Current.DeserializeObject(jsonString);
                    ProcessSubscription(context, jsonObject);
                }
                else
                {
                    HandleUnauthorizedRequest(context);
                }
            }

            break;
            }
        }
コード例 #5
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests. </param>
        public void ProcessRequest(HttpContext context)
        {
            Contract.Requires(context != null);
            Contract.Requires(context.Request != null);
            Contract.Requires(context.Request.Params != null);
            Contract.Requires(context.Response != null);

            var subContext = new FacebookSubscriptionContext
            {
                HttpContext         = new HttpContextWrapper(context),
                FacebookApplication = FacebookApplication.Current,
            };

            OnVerifying(subContext);
            VerifyCore(subContext);
        }
コード例 #6
0
 /// <summary>
 /// Set your verification token here.
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 public abstract void OnVerifying(FacebookSubscriptionContext context);
コード例 #7
0
 /// <summary>
 /// Handles unauthorized requests.
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 public virtual void HandleUnauthorizedRequest(FacebookSubscriptionContext context)
 {
     context.HttpContext.Response.StatusCode = 401;
 }
コード例 #8
0
 /// <summary>
 /// Process the subscription.
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 /// <param name="result">
 /// The result.
 /// </param>
 public abstract void ProcessSubscription(FacebookSubscriptionContext context, object result);
コード例 #9
0
 public override void ProcessSubscription(FacebookSubscriptionContext context, object result)
 {
     Contract.Requires(context != null);
     Contract.Requires(context.HttpContext.Request != null);
     Contract.Requires(context.HttpContext.Request.Params != null);
     Contract.Requires(context.HttpContext.Response != null);
 }
コード例 #10
0
 public override void OnVerifying(FacebookSubscriptionContext context)
 {
     Contract.Requires(context != null);
     Contract.Requires(context.HttpContext != null);
     Contract.Requires(context.FacebookApplication != null);
 }
コード例 #11
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContextWrapper"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests. </param>
        public virtual void VerifyCore(FacebookSubscriptionContext context)
        {
            Contract.Requires(context != null);
            Contract.Requires(context.HttpContext != null);
            Contract.Requires(context.HttpContext.Request != null);
            Contract.Requires(context.HttpContext.Request.Params != null);
            Contract.Requires(context.HttpContext.Response != null);
            Contract.Requires(context.FacebookApplication != null);

            context.HttpContext.Response.ContentType = "text/plain";
            var request = context.HttpContext.Request;

            string errorMessage;

            switch (request.HttpMethod)
            {
                case "GET":
                    if (!string.IsNullOrEmpty(context.VerificationToken) &&
                        FacebookSubscriptionVerifier.VerifyGetSubscription(request, context.VerificationToken, out errorMessage))
                    {
                        context.HttpContext.Response.Write(request.Params["hub.challenge"]);
                    }
                    else
                    {
                        HandleUnauthorizedRequest(context);
                    }

                    break;
                case "POST":
                    {
                        var reader = new System.IO.StreamReader(request.InputStream);
                        var jsonString = reader.ReadToEnd();

                        var secret = context.FacebookApplication.AppSecret;
                        if (!string.IsNullOrEmpty(secret) &&
                            FacebookSubscriptionVerifier.VerifyPostSubscription(request, secret, jsonString, out errorMessage))
                        {
                            // might need to put try catch when desterilizing object
                            var jsonObject = JsonSerializer.Current.DeserializeObject(jsonString);
                            ProcessSubscription(context, jsonObject);
                        }
                        else
                        {
                            HandleUnauthorizedRequest(context);
                        }
                    }

                    break;
            }
        }
コード例 #12
0
 /// <summary>
 /// Process the subscription.
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 /// <param name="result">
 /// The result.
 /// </param>
 public abstract void ProcessSubscription(FacebookSubscriptionContext context, object result);
コード例 #13
0
        /// <summary>
        /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"/> interface.
        /// </summary>
        /// <param name="context">An <see cref="T:System.Web.HttpContext"/> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests. </param>
        public void ProcessRequest(HttpContext context)
        {
            Contract.Requires(context != null);
            Contract.Requires(context.Request != null);
            Contract.Requires(context.Request.Params != null);
            Contract.Requires(context.Response != null);

            var subContext = new FacebookSubscriptionContext
                                 {
                                     HttpContext = new HttpContextWrapper(context),
                                     FacebookApplication = FacebookApplication.Current,
                                 };

            OnVerifying(subContext);
            VerifyCore(subContext);
        }
コード例 #14
0
 /// <summary>
 /// Set your verification token here.
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 public abstract void OnVerifying(FacebookSubscriptionContext context);
コード例 #15
0
 /// <summary>
 /// Handles unauthorized requests.
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 public virtual void HandleUnauthorizedRequest(FacebookSubscriptionContext context)
 {
     Contract.Requires(context != null);
     Contract.Requires(context.HttpContext != null);
     Contract.Requires(context.HttpContext.Response != null);
     context.HttpContext.Response.StatusCode = 401;
 }
コード例 #16
0
 public override void OnVerifying(FacebookSubscriptionContext context)
 {
     Contract.Requires(context != null);
     Contract.Requires(context.HttpContext != null);
     Contract.Requires(context.FacebookApplication != null);
 }