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); }
/// <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; }
/// <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); }
/// <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; } }
/// <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); }
/// <summary> /// Set your verification token here. /// </summary> /// <param name="context"> /// The context. /// </param> public abstract void OnVerifying(FacebookSubscriptionContext context);
/// <summary> /// Handles unauthorized requests. /// </summary> /// <param name="context"> /// The context. /// </param> public virtual void HandleUnauthorizedRequest(FacebookSubscriptionContext context) { context.HttpContext.Response.StatusCode = 401; }
/// <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);
public override void OnVerifying(FacebookSubscriptionContext context) { Contract.Requires(context != null); Contract.Requires(context.HttpContext != null); Contract.Requires(context.FacebookApplication != null); }