public void channel_data_is_encoded_as_JSON() { string channelName = "my-channel"; string socketId = "some_socket_id"; var serializer = new JsonSerializer(); PresenceChannelData data = new PresenceChannelData() { user_id = "unique_user_id", user_info = new { twitter_id = "@leggetter" } }; string expectedChannelData = serializer.Serialize(data); ; IAuthenticationData result = _pusher.Authenticate(channelName, socketId, data); Assert.AreEqual(expectedChannelData, result.channel_data); }
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 JsonResult AuthForChannel(string channel_name, string socket_id) { if (Session["user"] == null) { return(Json(new { status = "error", message = "User is not logged in" })); } var currentUser = (Models.User)Session["user"]; if (channel_name.IndexOf("presence") >= 0) { var channelData = new PresenceChannelData() { user_id = currentUser.Id.ToString(), user_info = new { id = currentUser.Id, name = currentUser.Name }, }; var presenceAuth = pusher.Authenticate(channel_name, socket_id, channelData); return(Json(presenceAuth)); } if (channel_name.IndexOf(currentUser.Id.ToString()) == -1) { return(Json(new { status = "error", message = "User cannot join channel" })); } var auth = pusher.Authenticate(channel_name, socket_id); return(Json(auth)); }
public AuthModule() { var provider = new Pusher(PusherApplicationID, PusherApplicationKey, PusherApplicationSecret); Post["/auth/{username}"] = parameters => { Console.WriteLine(String.Format("Processing auth request for '{0}' channel, for socket ID '{1}'", Request.Form.channel_name, Request.Form.socket_id)); string channel_name = Request.Form.channel_name; string socket_id = Request.Form.socket_id; if (channel_name.StartsWith("presence-")) { var channelData = new PresenceChannelData(); channelData.user_id = socket_id; channelData.user_info = new { name = parameters.name }; return(provider.Authenticate(channel_name, socket_id, channelData).ToJson()); } else { return(provider.Authenticate(channel_name, Request.Form.socket_id)); } }; }
public JsonResult AuthForChannel(string channel_name, string socket_id) { if (Session["user"] == null) { return(Json(new { status = "error", message = "User is not logged in" })); } var currentUser = (Models.User)Session["user"]; var channelData = new PresenceChannelData() { user_id = currentUser.id.ToString(), user_info = new { id = currentUser.id, name = currentUser.name }, }; var options = new PusherOptions(); options.Cluster = "PUSHER_APP_CLUSTER"; var pusher = new Pusher( "PUSHER_APP_ID", "PUSHER_APP_KEY", "PUSHER_APP_SECRET", options); var auth = pusher.Authenticate(channel_name, socket_id, channelData); return(Json(auth)); }
public AuthModule() { var provider = new Pusher(PusherApplicationId, PusherApplicationKey, PusherApplicationSecret); Post["/auth/{username}", ctx => ctx.Request.Form.channel_name && ctx.Request.Form.socket_id] = _ => { Console.WriteLine(string.Format("Processing auth request for '{0}' channel, for socket ID '{1}'", Request.Form.channel_name, Request.Form.socket_id)); string channelName = Request.Form.channel_name; string socketId = Request.Form.socket_id; string authData = null; if (channelName.StartsWith("presence-")) { var channelData = new PresenceChannelData { user_id = socketId, user_info = new { name = _.username } }; authData = provider.Authenticate(channelName, socketId, channelData).ToJson(); } else { authData = provider.Authenticate(channelName, socketId).ToJson(); } return(authData); }; }
public JsonResult AuthForChannel(string channel_name, string socket_id) { if (HttpContext.Session.GetInt32("user") == null) { return(Json(new { status = "error", message = "User is not logged in" })); } var id = HttpContext.Session.GetInt32("user"); if (channel_name.IndexOf("presence") >= 0) { var channelData = new PresenceChannelData() { user_id = HttpContext.Session.GetInt32("user").ToString(), user_info = new { id = HttpContext.Session.GetInt32("user"), name = TempData["username"] }, }; var presenceAuth = pusher.Authenticate(channel_name, socket_id, channelData); return(Json(presenceAuth)); } if (channel_name.IndexOf(HttpContext.Session.GetInt32("user").ToString()) == -1) { return(Json(new { status = "error", message = "User cannot join channel" })); } var auth = pusher.Authenticate(channel_name, socket_id); return(Json(auth)); }
public void null_presence_data_throw_Exception() { string channelName = "my-channel"; string socketId = "some_socket_id"; PresenceChannelData data = null; _pusher.Authenticate(channelName, socketId, data); }
public ActionResult PusherAuth(string channelNameX, string socketIdX) { Request.Form.TryGetValue("socket_id", out var socketId); Request.Form.TryGetValue("channel_name", out var channelNames); //if (channelName == null) // return new OkResult(); var channelName = channelNames[0]; { var options = new PusherOptions { Encrypted = true, Cluster = Globals.PusherCluster }; var pusher = new Pusher(Globals.PusherAppId, Globals.PusherKey, Globals.PusherSecret, options); if (!_signInManager.IsSignedIn(User)) { return(new UnauthorizedResult()); } if (channelName.StartsWith("private-")) { var auth = pusher.Authenticate(channelName, socketId); var json = auth.ToJson(); return(new ContentResult { Content = json, ContentType = "application/json" }); } //else if (channelName.StartsWith("presence-")) { string prefix = Request.IsHttps ? "https://" : "http://"; var channelData = new PresenceChannelData() { user_id = _userManager.GetUserId(User), user_info = new { name = NoteDataManager.GetSafeUserDisplayName(_userManager, User, _db), host_name = Environment.MachineName, base_url = prefix + Request.Host.Value } }; var auth = pusher.Authenticate(channelName, socketId, channelData); var json = auth.ToJson(); return(new ContentResult { Content = json, ContentType = "application/json" }); } } // should never happen //return new OkResult(); }
public void ProcessRequest(HttpContext context) { SetupDefaultProvider(context); PresenceChannelData channelData = new PresenceChannelData { user_id = socketID, user_info = new BasicUserInfo { name = memberName } }; var helper = new PusherAuthenticationHelper(applicationId, applicationKey, applicationSecret); string authJson = helper.CreateAuthenticatedString(socketID, channelName, channelData); context.Response.Write(authJson); }
public void channel_data_is_encoded_as_JSON() { string channelName = "my-channel"; string socketId = "123.456"; PresenceChannelData data = new PresenceChannelData() { user_id = "unique_user_id", user_info = new { twitter_id = "@leggetter" } }; string expectedChannelData = JsonConvert.SerializeObject(data); IAuthenticationData result = _pusher.Authenticate(channelName, socketId, data); Assert.AreEqual(expectedChannelData, result.channel_data); }
public void channel_data_is_encoded_as_JSON() { string channelName = "my-channel"; string socketId = "123.456"; PresenceChannelData data = new PresenceChannelData() { user_id = "unique_user_id", user_info = new { twitter_id = "@leggetter" } }; string expectedChannelData = DefaultSerializer.Default.Serialize(data); IAuthenticationData result = _pusher.Authenticate(channelName, socketId, data); Assert.AreEqual(expectedChannelData, result.channel_data); }
public ActionResult Auth(string channel_name, string socket_id) { Debug.WriteLine("trying to auth"); var pusher = new Pusher("72484", "e9473350e86cf2fd89ac", "3e1cbae89445267f362f"); var channelData = new PresenceChannelData(); channelData.user_id = (string)Session["FBID"]; channelData.user_info = new { facebook_id = (string)Session["FBID"] }; var auth = pusher.Authenticate(channel_name, socket_id, channelData); var json = auth.ToJson(); return(new ContentResult { Content = json, ContentType = "application/json" }); }
public void the_auth_response_is_valid() { string channelName = "my-channel"; string socketId = "123.456"; PresenceChannelData data = new PresenceChannelData() { user_id = "unique_user_id", user_info = new { twitter_id = "@leggetter" } }; string presenceJson = JsonConvert.SerializeObject(data); string expectedAuthString = Config.AppKey + ":" + CreateSignedString(channelName, socketId, presenceJson); IAuthenticationData result = _pusher.Authenticate(channelName, socketId, data); Assert.AreEqual(expectedAuthString, result.auth); }
public void the_auth_response_is_valid() { string channelName = "my-channel"; string socketId = "123.456"; PresenceChannelData data = new PresenceChannelData() { user_id = "unique_user_id", user_info = new { twitter_id = "@leggetter" } }; string presenceJson = DefaultSerializer.Default.Serialize(data); string expectedAuthString = Config.AppKey + ":" + CreateSignedString(channelName, socketId, presenceJson); IAuthenticationData result = _pusher.Authenticate(channelName, socketId, data); Assert.AreEqual(expectedAuthString, result.auth); }
public AuthModule() { PusherServer.PusherOptions options = new PusherServer.PusherOptions { EncryptionMasterKey = Convert.FromBase64String(EncryptionMasterKeyText), Cluster = Config.Cluster, }; var provider = new PusherServer.Pusher(PusherApplicationId, PusherApplicationKey, PusherApplicationSecret, options); Post["/auth/{username}", ctx => ctx.Request.Form.channel_name && ctx.Request.Form.socket_id] = _ => { Console.WriteLine($"Processing auth request for '{Request.Form.channel_name}' channel, for socket ID '{Request.Form.socket_id}'"); string channelName = Request.Form.channel_name; string socketId = Request.Form.socket_id; string authData = null; if (Channel.GetChannelType(channelName) == ChannelTypes.Presence) { var channelData = new PresenceChannelData { user_id = socketId, user_info = new { Name = _.username.ToString() } }; authData = provider.Authenticate(channelName, socketId, channelData).ToJson(); } else { authData = provider.Authenticate(channelName, socketId).ToJson(); } if (Channel.GetChannelType(channelName) == ChannelTypes.PrivateEncrypted) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed SendSecretMessageAsync(); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } return(authData); }; }
public string Authorize(string channelName, string socketId) { var provider = new PusherServer.Pusher(Config.AppId, Config.AppKey, Config.AppSecret); string authData; if (channelName.StartsWith("presence-")) { var channelData = new PresenceChannelData(); channelData.user_id = socketId; channelData.user_info = new { name = _userName }; authData = provider.Authenticate(channelName, socketId, channelData).ToJson(); } else { authData = provider.Authenticate(channelName, socketId).ToJson(); } return(authData); }
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" }); }
public static string Authenticate(string socket_id, string channel_name) { if (channel_name.IndexOf("presence-chat") >= 0) { var channelData = new PresenceChannelData() { user_id = uniqueID.ToString(), user_info = new { id = uniqueID }, }; var presenceAuth = pusher.Authenticate(channel_name, socket_id, channelData); return(JsonConvert.SerializeObject(presenceAuth)); } var auth = pusher.Authenticate(channel_name, socket_id); return(JsonConvert.SerializeObject(auth)); }
public async Task <string> AuthorizeAsync(string channelName, string socketId) { string authData = null; double delay = (await LatencyInducer.InduceLatencyAsync(MinLatency, MaxLatency)) / 1000.0; Trace.TraceInformation($"{this.GetType().Name} paused for {Math.Round(delay, 3)} second(s)"); await Task.Run(() => { PusherServer.PusherOptions options = new PusherServer.PusherOptions { EncryptionMasterKey = _encryptionKey, Cluster = Config.Cluster, }; var provider = new PusherServer.Pusher(Config.AppId, Config.AppKey, Config.AppSecret, options); if (channelName.StartsWith("presence-")) { var channelData = new PresenceChannelData { user_id = socketId, user_info = new FakeUserInfo { name = _userName } }; authData = provider.Authenticate(channelName, socketId, channelData).ToJson(); } else { authData = provider.Authenticate(channelName, socketId).ToJson(); } if (channelName.Contains(TamperToken)) { authData = authData.Replace("1", "2"); } }).ConfigureAwait(false); return(authData); }
public void Auth(string channel_name, string socket_id, int userID) { Users u = new Users(TSAuthentication.GetLoginUser()); u.LoadByUserID(userID); var channelData = new PresenceChannelData() { user_id = userID.ToString(), user_info = new { name = TSAuthentication.GetLoginUser().GetUserFullName(), userid = userID.ToString(), avatar = string.Format("/dc/{0}/UserAvatar/{1}/120", u[0].OrganizationID.ToString(), userID) } }; var auth = pusher.Authenticate(channel_name, socket_id, channelData); var json = auth.ToJson(); Context.Response.Write(json); }
public InMemoryAuthorizer(PusherServer.Pusher pusher, PresenceChannelData presenceData) { _pusher = pusher; _presenceData = presenceData; }
public string Authenticate(string channelName, string socketId, PresenceChannelData presenceChannelData) { return(_authHelper.CreateAuthenticatedString(socketId, channelName, presenceChannelData)); }