// 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 ProcessRequest(HttpContext context) { SetupDefaultProvider(context); var provider = new PusherProvider(applicationId, applicationKey, applicationSecret); string authJson = provider.Authenticate(socketID, channelName); context.Response.Write(authJson); }
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 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" }); }