public void BlowsUpOnTriggerPushWithBadCredentials()
        {
            var request = new TestPusherRequest("test_channel", "my_event", @"{""some"":""data""}");

            var provider = new PusherProvider("meh", "foo", "bar");
            provider.Trigger(request);
        }
        // GET: /Pusher/Auth
        public ContentResult Auth(string username)
        {
            // Connect to Pusher REST API
            var    provider = new PusherProvider(SETTING_PUSHER_APPID, SETTING_PUSHER_KEY, SETTING_PUSHER_SECRET);
            string result   = null;

            // Gather channel name and socket id
            string channel_name = Request.Form["channel_name"];
            string socket_id    = Request.Form["socket_id"];

            // If presence channel
            if (channel_name.StartsWith("presence-"))
            {
                var userInfo = new BasicUserInfo();
                userInfo.name = username;

                result = provider.Authenticate(channel_name, socket_id,
                                               new PusherRESTDotNet.Authentication.PresenceChannelData()
                {
                    user_id   = socket_id,
                    user_info = userInfo
                });
            }
            // If private channel
            else if (channel_name.StartsWith("private-"))
            {
                result = provider.Authenticate(channel_name, socket_id);
            }

            return(new ContentResult()
            {
                Content = result
            });
        }
        public ActionResult Auth(string channel_name, string socket_id)
        {
            var applicationId     = ConfigurationManager.AppSettings["pusher_app_id"];
            var applicationKey    = ConfigurationManager.AppSettings["pusher_key"];
            var applicationSecret = ConfigurationManager.AppSettings["pusher_secret"];

            //var channelData = new PresenceChannelData()
            //{
            //    user_id = Guid.NewGuid().ToString()
            //};
            var channelData = new PresenceChannelData();

            if (User.Identity.IsAuthenticated)
            {
                channelData.user_id = User.Identity.Name;
            }
            else
            {
                channelData.user_id = Guid.NewGuid().ToString();
            }
            channelData.user_info = new PusherUserInfo();

            var    provider = new PusherProvider(applicationId, applicationKey, applicationSecret);
            string authJson = provider.Authenticate(channel_name, socket_id, channelData);

            return(new ContentResult {
                Content = authJson, ContentType = "application/json"
            });
        }
        public void BlowsUpOnTriggerPushWithBadCredentials()
        {
            var request = new TestPusherRequest("test_channel", "my_event", @"{""some"":""data""}");

            var provider = new PusherProvider("meh", "foo", "bar");

            provider.Trigger(request);
        }
Exemple #5
0
        public void ProcessRequest(HttpContext context)
        {
            SetupDefaultProvider(context);

            var    provider = new PusherProvider(applicationId, applicationKey, applicationSecret);
            string authJson = provider.Authenticate(socketID, channelName);

            context.Response.Write(authJson);
        }
        public void SetupDefaultProvider()
        {
            if (String.IsNullOrEmpty(applicationId))
                Assert.Fail("applicationId not specified in app.config appSettings");
            if (String.IsNullOrEmpty(applicationKey))
                Assert.Fail("applicationKey not specified in app.config appSettings");
            if (String.IsNullOrEmpty(applicationSecret))
                Assert.Fail("applicationSecret not specified in app.config appSettings");

            _defaultProvider = new PusherProvider(applicationId, applicationKey, applicationSecret);
        }
        // GET: /Pusher/AddSquare
        public EmptyResult AddSquare(string squareId, string socketId)
        {
            var provider = new PusherProvider(SETTING_PUSHER_APPID, SETTING_PUSHER_KEY, SETTING_PUSHER_SECRET);

            provider.Trigger(new ObjectPusherRequest(SETTING_PUSHER_CHANNEL, "add-square", new
            {
                squareId            = squareId,
                originatingSocketId = socketId
            }
                                                     ));

            return(new EmptyResult());
        }
        // GET: /Pusher/MoveSquare
        public EmptyResult MoveSquare(string squareId, int top, int left, string socketId)
        {
            var provider = new PusherProvider(SETTING_PUSHER_APPID, SETTING_PUSHER_KEY, SETTING_PUSHER_SECRET);

            provider.Trigger(new ObjectPusherRequest(SETTING_PUSHER_CHANNEL, "update-square", new
            {
                squareId            = squareId,
                top                 = top,
                left                = left,
                originatingSocketId = socketId
            }
                                                     ));

            return(new EmptyResult());
        }
        public void SetupDefaultProvider()
        {
            var applicationId = ConfigurationManager.AppSettings["applicationId"];
            var applicationKey = ConfigurationManager.AppSettings["applicationKey"];
            var applicationSecret = ConfigurationManager.AppSettings["applicationSecret"];

            if (String.IsNullOrEmpty(applicationId))
                Assert.Fail("applicationId not specified in app.config appSettings");
            if (String.IsNullOrEmpty(applicationKey))
                Assert.Fail("applicationKey not specified in app.config appSettings");
            if (String.IsNullOrEmpty(applicationSecret))
                Assert.Fail("applicationSecret not specified in app.config appSettings");

            _defaultProvider = new PusherProvider(applicationId, applicationKey, applicationSecret);
        }
        public void AuthenticationStringIsCorrectlyFormedForPrivateChannel()
        {
            var appId = "1000";
            var appKey = "myAppKey";
            var appSecret = "myAppSecret";
            var channelName = "private-channel";
            var socketId = "socket_id";
            var helper = new PusherAuthenticationHelper(appId, appKey, appSecret);
            var expected = helper.CreateAuthenticatedString(socketId, channelName);

            IPusherProvider provider = new PusherProvider(appId, appKey, appSecret);
            string auth = provider.Authenticate(channelName, socketId);

            Assert.IsNotNullOrEmpty(auth);
            Assert.AreEqual(expected, auth);
        }
Exemple #11
0
        public void AuthenticationStringIsCorrectlyFormedForPrivateChannel()
        {
            var appId       = "1000";
            var appKey      = "myAppKey";
            var appSecret   = "myAppSecret";
            var channelName = "private-channel";
            var socketId    = "socket_id";
            var helper      = new PusherAuthenticationHelper(appId, appKey, appSecret);
            var expected    = helper.CreateAuthenticatedString(socketId, channelName);

            IPusherProvider provider = new PusherProvider(appId, appKey, appSecret);
            string          auth     = provider.Authenticate(channelName, socketId);

            Assert.IsNotNullOrEmpty(auth);
            Assert.AreEqual(expected, auth);
        }
        public void SetupDefaultProvider()
        {
            if (String.IsNullOrEmpty(applicationId))
            {
                Assert.Fail("applicationId not specified in app.config appSettings");
            }
            if (String.IsNullOrEmpty(applicationKey))
            {
                Assert.Fail("applicationKey not specified in app.config appSettings");
            }
            if (String.IsNullOrEmpty(applicationSecret))
            {
                Assert.Fail("applicationSecret not specified in app.config appSettings");
            }

            _defaultProvider = new PusherProvider(applicationId, applicationKey, applicationSecret);
        }
        public void AuthenticationStringIsCorrectlyFormedForPresenceChannel()
        {
            var appId = "1000";
            var appKey = "myAppKey";
            var appSecret = "myAppSecret";
            var channelName = "presence-channel";
            var presenceChannelData = new PresenceChannelData()
            {
                user_id = "leggetter",
                user_info = new { name = "Phil Leggetter", twitter = "@leggetter" }
            };
            var socketId = "socket_id";
            var helper = new PusherAuthenticationHelper(appId, appKey, appSecret);
            string expected = helper.CreateAuthenticatedString(socketId, channelName, presenceChannelData);

            IPusherProvider provider = new PusherProvider(appId, appKey, appSecret);
            string auth = provider.Authenticate(channelName, socketId, presenceChannelData);

            Assert.IsNotNullOrEmpty(auth);
            Assert.AreEqual(expected, auth);
        }
Exemple #14
0
        public void AuthenticationStringIsCorrectlyFormedForPresenceChannel()
        {
            var appId               = "1000";
            var appKey              = "myAppKey";
            var appSecret           = "myAppSecret";
            var channelName         = "presence-channel";
            var presenceChannelData = new PresenceChannelData()
            {
                user_id   = "leggetter",
                user_info = new { name = "Phil Leggetter", twitter = "@leggetter" }
            };
            var    socketId = "socket_id";
            var    helper   = new PusherAuthenticationHelper(appId, appKey, appSecret);
            string expected = helper.CreateAuthenticatedString(socketId, channelName, presenceChannelData);

            IPusherProvider provider = new PusherProvider(appId, appKey, appSecret);
            string          auth     = provider.Authenticate(channelName, socketId, presenceChannelData);

            Assert.IsNotNullOrEmpty(auth);
            Assert.AreEqual(expected, auth);
        }
        public ActionResult Auth(string channel_name, string socket_id)
        {
            var channelData = new PresenceChannelData();

            if (User.Identity.IsAuthenticated)
            {
                channelData.user_id = User.Identity.Name;
            }
            else
            {
                channelData.user_id = GetUniqueUserId();
            }
            channelData.user_info = GetUserInfo();

            var    provider = new PusherProvider(applicationId, applicationKey, applicationSecret);
            string authJson = provider.Authenticate(channel_name, socket_id, channelData);

            return(new ContentResult {
                Content = authJson, ContentType = "application/json"
            });
        }