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 string CreateAuthenticatedString(string socketID, string channelName, PresenceChannelData channelData) { string channel = (channelData == null?"":JsonConvert.SerializeObject(channelData)); string auth = AuthSignatureHelper.GetAuthString(socketID + ":" + channelName + ":" + channel, applicationSecret); AuthData data = new AuthData(); data.auth = applicationKey + ":" + auth; data.channel_data = channel; string json = JsonConvert.SerializeObject(data); return json; }
public string CreateAuthenticatedString(string socketID, string channelName, PresenceChannelData channelData) { string channel = (channelData == null?"":JsonConvert.SerializeObject(channelData)); string auth = AuthSignatureHelper.GetAuthString(socketID + ":" + channelName + ":" + channel, applicationSecret); AuthData data = new AuthData(); data.auth = applicationKey + ":" + auth; data.channel_data = channel; string json = JsonConvert.SerializeObject(data); return(json); }
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" }; }
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 string Authenticate(string channelName, string socketId, PresenceChannelData presenceChannelData) { return _authHelper.CreateAuthenticatedString(socketId, channelName, presenceChannelData); }