public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            filterContext.HttpContext.Response.ContentType = "text/plain";
            var request    = filterContext.HttpContext.Request;
            var modelState = filterContext.Controller.ViewData.ModelState;

            string errorMessage;

            if (request.HttpMethod == "GET")
            {
                if (string.IsNullOrEmpty(VerificationToken))
                {
                    errorMessage = "Verification Token is empty.";
                }
                else
                {
                    if (FacebookSubscriptionVerifier.VerifyGetSubscription(request, VerificationToken, out errorMessage))
                    {
                        return;
                    }
                }
            }
            else
            {
                errorMessage = "Invalid http method.";
            }

            modelState.AddModelError("facebook-subscription", errorMessage);

            filterContext.HttpContext.Response.StatusCode = 401;
        }
Beispiel #2
0
        public void ErrorMessageIsSetCorrectly()
        {
            var    request = GetRequest();
            string errorMessage;

            var result = FacebookSubscriptionVerifier.VerifyGetSubscription(request, "dummy verify token", out errorMessage);

            Assert.Equal(Properties.Resources.InvalidHubMode, errorMessage);
        }
Beispiel #3
0
        public void ErrorMessageIsNotNull()
        {
            var    request = GetRequest();
            string errorMessage;

            var result = FacebookSubscriptionVerifier.VerifyGetSubscription(request, "dummy verify token", out errorMessage);

            Assert.NotNull(errorMessage);
        }
Beispiel #4
0
        public void ReturnsFalse()
        {
            var    request = GetRequest();
            string errorMessage;

            var result = FacebookSubscriptionVerifier.VerifyGetSubscription(request, "dummy verify token", out errorMessage);

            Assert.False(result);
        }
        public void ReturnsTrue()
        {
            var    request = GetRequest();
            string errorMessage;

            var result = FacebookSubscriptionVerifier.VerifyGetSubscription(request, "correct_verify_token", out errorMessage);

            Assert.True(result);
        }
Beispiel #6
0
        public void ErrorMessageIsSetCorrectly()
        {
            var    request = GetRequest();
            string errorMessage;
            string dummyJson = "{}";

            var result = FacebookSubscriptionVerifier.VerifyPostSubscription(request, "dummy_secret", dummyJson, out errorMessage);

            Assert.Equal(Properties.Resources.InvalidHttpXHubSignature, errorMessage);
        }
Beispiel #7
0
        public void ErrorMessageIsNotNull()
        {
            var    request = GetRequest();
            string errorMessage;
            string dummyJson = "{}";

            var result = FacebookSubscriptionVerifier.VerifyPostSubscription(request, "dummy_secret", dummyJson, out errorMessage);

            Assert.NotNull(errorMessage);
        }
Beispiel #8
0
        public void ReturnsFalse()
        {
            var    request = GetRequest();
            string errorMessage;
            string dummyJson = "{}";

            var result = FacebookSubscriptionVerifier.VerifyPostSubscription(request, "dummy_secret", dummyJson, out errorMessage);

            Assert.False(result);
        }
        public void ErrorMessageIsNull()
        {
            var    request = GetRequest();
            string errorMessage;
            string secret     = "18b8c40f4e48e2616a0c548ec96fdeb2";
            string jsonString = "{\"object\":\"user\",\"entry\":[{\"uid\":\"100000326364373\",\"id\":\"100000326364373\",\"time\":1297087737,\"changed_fields\":[\"feed\"]}]}";

            var result = FacebookSubscriptionVerifier.VerifyPostSubscription(request, secret, jsonString, out errorMessage);

            Assert.Null(errorMessage);
        }
Beispiel #10
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            filterContext.HttpContext.Response.ContentType = "text/plain";
            var request    = filterContext.HttpContext.Request;
            var modelState = filterContext.Controller.ViewData.ModelState;
            var appSecret  = FacebookApplication.Current.AppSecret;

            var parameterName = ParameterName;

            if (string.IsNullOrEmpty(parameterName))
            {
                parameterName = "subscription";
            }

            filterContext.ActionParameters[parameterName] = null;

            string errorMessage;

            if (request.HttpMethod == "POST")
            {
                if (string.IsNullOrEmpty(appSecret))
                {
                    errorMessage = "FacebookContext.Current.AppSecret is null or empty.";
                }
                else
                {
                    var reader     = new System.IO.StreamReader(request.InputStream);
                    var jsonString = reader.ReadToEnd();

                    if (FacebookSubscriptionVerifier.VerifyPostSubscription(request, appSecret, jsonString, out errorMessage))
                    {
                        var jsonObject = JsonSerializer.Current.DeserializeObject(jsonString);
                        filterContext.ActionParameters[parameterName] = jsonObject;

                        return;
                    }
                }
            }
            else
            {
                errorMessage = "Invalid http method.";
            }

            modelState.AddModelError("facebook-subscription", errorMessage);

            filterContext.HttpContext.Response.StatusCode = 401;
        }