Exemplo n.º 1
0
        public void Session_GivenARequestWithNoSignedRequestAndFbSessionCookie_ThenItShouldReturnNull()
        {
            var requestParams = new NameValueCollection();
            var httpContext = GetHttpContext(requestParams);

            var authorizer =
                new FacebookWebAuthorizer(new DefaultFacebookApplication { AppId = "dummy", AppSecret = "dummy" },
                                          httpContext);
            var session = authorizer.FacebookWebRequest.Session;

            Assert.Null(session);
        }
Exemplo n.º 2
0
        public void Session_GivenARequestWithValidSignedRequestAndNoFbSessionCookieAndInvalidAppsecret_ThenItShouldThrowInvalidOperationException()
        {
            var requestParams = new NameValueCollection
                                    {
                                        { "signed_request", "Iin8a5nlQOHhlvHu_4lNhKDDvut6s__fm6-jJytkHis.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEyODI5Mjg0MDAsIm9hdXRoX3Rva2VuIjoiMTIwNjI1NzAxMzAxMzQ3fDIuSTNXUEZuXzlrSmVnUU5EZjVLX0kyZ19fLjM2MDAuMTI4MjkyODQwMC0xNDgxMjAxN3xxcmZpT2VwYnY0ZnN3Y2RZdFJXZkFOb3I5YlEuIiwidXNlcl9pZCI6IjE0ODEyMDE3In0" }
                                    };

            var httpContext = GetHttpContext(requestParams);
            var authorizer = new FacebookWebAuthorizer(
                new DefaultFacebookApplication { AppId = "dummy", AppSecret = "invalid_secret" }, httpContext);

            Assert.Throws<InvalidOperationException>(() => authorizer.FacebookWebRequest.Session);
        }
Exemplo n.º 3
0
        public void Session_GivenARequestWithNoSignedRequestAndFbSessionCookie_ThenItShouldReturnNull()
        {
            var requestParams = new NameValueCollection();
            var httpContext   = GetHttpContext(requestParams);

            var authorizer =
                new FacebookWebAuthorizer(new DefaultFacebookApplication {
                AppId = "dummy", AppSecret = "dummy"
            },
                                          httpContext);
            var session = authorizer.FacebookWebRequest.Session;

            Assert.Null(session);
        }
Exemplo n.º 4
0
        public void Session_GivenARequestWithValidSessionCookieAndNoSignedRequestAndValidSecret_ThenItShouldNotReturnNull()
        {
            var appId = "124973200873702";
            var appSecret = "3b4a872617be2ae1932baa1d4d240272";
            var requestParams = new NameValueCollection { { "fbs_" + appId, "access_token=124973200873702%7C2.OAaqICOCk_B4sZNv59q8Yg__.3600.1295118000-100001327642026%7Cvz4H9xjlRZPfg2quCv0XOM5g9_o&expires=1295118000&secret=lddpssZCuPoEtjcDFcWtoA__&session_key=2.OAaqICOCk_B4sZNv59q8Yg__.3600.1295118000-100001327642026&sig=1d95fa4b3dfa5b26c01c8ac8676d80b8&uid=100001327642026" } };

            var httpContext = GetHttpContext(requestParams);

            var authorizer = new FacebookWebAuthorizer(
                new DefaultFacebookApplication { AppId = appId, AppSecret = appSecret }, httpContext);

            var session = authorizer.FacebookWebRequest.Session;

            Assert.NotNull(session);
        }
Exemplo n.º 5
0
        public void Session_GivenARequestWithValidSignedRequestAndNoFbSessionCookieAndInvalidAppsecret_ThenItShouldThrowInvalidOperationException()
        {
            var requestParams = new NameValueCollection
            {
                { "signed_request", "Iin8a5nlQOHhlvHu_4lNhKDDvut6s__fm6-jJytkHis.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEyODI5Mjg0MDAsIm9hdXRoX3Rva2VuIjoiMTIwNjI1NzAxMzAxMzQ3fDIuSTNXUEZuXzlrSmVnUU5EZjVLX0kyZ19fLjM2MDAuMTI4MjkyODQwMC0xNDgxMjAxN3xxcmZpT2VwYnY0ZnN3Y2RZdFJXZkFOb3I5YlEuIiwidXNlcl9pZCI6IjE0ODEyMDE3In0" }
            };

            var httpContext = GetHttpContext(requestParams);
            var authorizer  = new FacebookWebAuthorizer(
                new DefaultFacebookApplication {
                AppId = "dummy", AppSecret = "invalid_secret"
            }, httpContext);

            Assert.Throws <InvalidOperationException>(() => authorizer.FacebookWebRequest.Session);
        }
Exemplo n.º 6
0
        public ActionResult About()
        {
            FacebookWebAuthorizer fwa = new FacebookWebAuthorizer(new PraLoupFacebookApplication(), HttpContext);

            fwa.Permissions   = new string[] { "publish_stream" };
            fwa.ReturnUrlPath = HttpContext.Request.Url.ToString();
            if (fwa.Authorize())
            {
                var oAuth = new OAuthHandler();

                //Get the access token and secret.
                oAuth.Token = FacebookWebContext.Current.AccessToken;
                Friends      f  = new Friends(oAuth);
                FriendsLists fl = new FriendsLists(oAuth);
            }

            return(View());
        }
Exemplo n.º 7
0
        public void Session_GivenARequestWithValidSessionCookieAndNoSignedRequestAndValidSecret_ThenItShouldNotReturnNull()
        {
            var appId         = "124973200873702";
            var appSecret     = "3b4a872617be2ae1932baa1d4d240272";
            var requestParams = new NameValueCollection {
                { "fbs_" + appId, "access_token=124973200873702%7C2.OAaqICOCk_B4sZNv59q8Yg__.3600.1295118000-100001327642026%7Cvz4H9xjlRZPfg2quCv0XOM5g9_o&expires=1295118000&secret=lddpssZCuPoEtjcDFcWtoA__&session_key=2.OAaqICOCk_B4sZNv59q8Yg__.3600.1295118000-100001327642026&sig=1d95fa4b3dfa5b26c01c8ac8676d80b8&uid=100001327642026" }
            };

            var httpContext = GetHttpContext(requestParams);

            var authorizer = new FacebookWebAuthorizer(
                new DefaultFacebookApplication {
                AppId = appId, AppSecret = appSecret
            }, httpContext);

            var session = authorizer.FacebookWebRequest.Session;

            Assert.NotNull(session);
        }
Exemplo n.º 8
0
        public void Session_GivenARequestWithValidSessionCookieSignedRequestAppIdAndSecret_ThenItShouldNotReturnNull()
        {
            var appId         = "dummy";
            var appSecret     = "543690fae0cd186965412ac4a49548b5";
            var requestParams = new NameValueCollection
            {
                { "signed_request", "Iin8a5nlQOHhlvHu_4lNhKDDvut6s__fm6-jJytkHis.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEyODI5Mjg0MDAsIm9hdXRoX3Rva2VuIjoiMTIwNjI1NzAxMzAxMzQ3fDIuSTNXUEZuXzlrSmVnUU5EZjVLX0kyZ19fLjM2MDAuMTI4MjkyODQwMC0xNDgxMjAxN3xxcmZpT2VwYnY0ZnN3Y2RZdFJXZkFOb3I5YlEuIiwidXNlcl9pZCI6IjE0ODEyMDE3In0" },
                { "fbs_" + appId, "access_token=124973200873702%7C2.OAaqICOCk_B4sZNv59q8Yg__.3600.1295118000-100001327642026%7Cvz4H9xjlRZPfg2quCv0XOM5g9_o&expires=1295118000&secret=lddpssZCuPoEtjcDFcWtoA__&session_key=2.OAaqICOCk_B4sZNv59q8Yg__.3600.1295118000-100001327642026&sig=1d95fa4b3dfa5b26c01c8ac8676d80b8&uid=100001327642026" }
            };
            var httpContext = GetHttpContext(requestParams);

            var authorizer = new FacebookWebAuthorizer(
                new DefaultFacebookApplication {
                AppId = appId, AppSecret = appSecret
            }, httpContext);

            var session = authorizer.FacebookWebRequest.Session;

            Assert.NotNull(session);
        }
Exemplo n.º 9
0
        public ActionResult Login()
        {
            if (!FacebookWebContext.Current.IsAuthenticated())
            {
                return(View());
            }
            else
            {
                try
                {
                    Register();
                }
                catch (Exception)
                {
                    return(View());
                }
                FacebookWebAuthorizer fwa = new FacebookWebAuthorizer(new PraLoupFacebookApplication(), HttpContext);
                fwa.Permissions   = new string[] { "publish_stream", "user_about_me", "read_friendlists", "user_photos", "friends_photos" };
                fwa.ReturnUrlPath = returnUrl;
                fwa.CancelUrlPath = returnUrl;
                if (fwa.Authorize())
                {
                    string url = null;
                    if (FacebookWebContext.Current.HttpContext.Request.UrlReferrer != null)
                    {
                        url = FacebookWebContext.Current.HttpContext.Request.UrlReferrer.ToString();
                    }

                    if (string.IsNullOrEmpty(url))
                    {
                        return(RedirectToAction("Create", "Promotion", new { area = "Business" }));
                    }
                    else
                    {
                        return(Redirect(url));
                    }
                }
                return(View());
            }
        }
Exemplo n.º 10
0
        public void Session_GivenARequestWithValidSessionCookieSignedRequestAppIdAndSecret_ThenTheAccessTokenShouldBeEqualToThatOfSignedRequest()
        {
            var appId = "dummy";
            var appSecret = "543690fae0cd186965412ac4a49548b5";
            var requestParams = new NameValueCollection
                                    {
                                        { "signed_request", "Iin8a5nlQOHhlvHu_4lNhKDDvut6s__fm6-jJytkHis.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEyODI5Mjg0MDAsIm9hdXRoX3Rva2VuIjoiMTIwNjI1NzAxMzAxMzQ3fDIuSTNXUEZuXzlrSmVnUU5EZjVLX0kyZ19fLjM2MDAuMTI4MjkyODQwMC0xNDgxMjAxN3xxcmZpT2VwYnY0ZnN3Y2RZdFJXZkFOb3I5YlEuIiwidXNlcl9pZCI6IjE0ODEyMDE3In0" },
                                        { "fbs_" + appId, "access_token=124973200873702%7C2.OAaqICOCk_B4sZNv59q8Yg__.3600.1295118000-100001327642026%7Cvz4H9xjlRZPfg2quCv0XOM5g9_o&expires=1295118000&secret=lddpssZCuPoEtjcDFcWtoA__&session_key=2.OAaqICOCk_B4sZNv59q8Yg__.3600.1295118000-100001327642026&sig=1d95fa4b3dfa5b26c01c8ac8676d80b8&uid=100001327642026" }
                                    };
            var httpContext = GetHttpContext(requestParams);

            var authorizer = new FacebookWebAuthorizer(
                new DefaultFacebookApplication { AppId = appId, AppSecret = appSecret }, httpContext);

            var session = authorizer.FacebookWebRequest.Session;
            var accessToken = session.AccessToken;

            Assert.Equal("120625701301347|2.I3WPFn_9kJegQNDf5K_I2g__.3600.1282928400-14812017|qrfiOepbv4fswcdYtRWfANor9bQ.", accessToken);
        }