コード例 #1
1
        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 channel_name = Request.Form.channel_name;
                string socket_id = Request.Form.socket_id;

                string authData = null;

                if (channel_name.StartsWith("presence-"))
                {
                    var channelData = new PresenceChannelData();
                    channelData.user_id = socket_id;
                    channelData.user_info = new { name = _.username };

                    authData = provider.Authenticate(channel_name, socket_id, channelData).ToJson();
                }
                else
                {
                    authData = provider.Authenticate(channel_name, socket_id).ToJson();
                }

                return authData;
            };
        }
コード例 #2
0
        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));
                }
            };
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);
            };
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        public JsonResult AuthForChannel(string channel_name, string socket_id)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            string userId           = User.Identity.GetUserId();
            var    currentUser      = db.Musicians.Where(u => u.UserId == userId).First();

            if (currentUser == null)
            {
                return(Json(new { status = "error", message = "User is not logged in" }));
            }


            var options = new PusherOptions();

            options.Cluster = APIUtility.PusherCluster;

            var pusher = new Pusher(
                APIUtility.PusherAppId,
                APIUtility.PusherKey,
                APIUtility.PusherSecretKey, options);

            //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));
        }
コード例 #8
0
        //In the code above, we check if a user exists using the name. If it exists we retrieve the user’s details and, if it doesn’t, we create a new record first.
        //Then we assign the user’s details into a session object for use throughout the application. Lastly, we redirect the user to the chat page.

        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 options = new PusherOptions();

            options.Cluster = "PUSHER_APP_CLUSTER";

            var pusher = new Pusher(
                "PUSHER_APP_ID",
                "PUSHER_APP_KEY",
                "PUSHER_APP_SECRET", options);

            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));
        }
コード例 #9
0
        public JsonResult AuthForChannel(string channel_name, string socket_id)
        {
            var currentUser = db.UsuariosAsps.Where(u => u.UserName == User.Identity.Name)
                              .ToList()[0];

            var options = new PusherOptions();

            options.Cluster = "us2";

            var pusher = new Pusher(
                "530632",
                "ed5c2354a385822ffe87",
                "0314372fa7f33ce2837a", options);

            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));
        }
コード例 #10
0
        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));
        }
コード例 #11
0
        public object Post([FromBody] AuthPusher authpusher)
        {
            var pusher = new Pusher("318710", "e566743c8d2d940b3849", "6a71cf9d67948c9fd93e");
            var auth   = pusher.Authenticate(authpusher.channel_name, authpusher.socket_id);
            var json   = auth.ToJson();

            return(auth);
        }
コード例 #12
0
        public ActionResult Auth(string channel_name, string socket_id)
        {
            var pusher = new Pusher(_pusherOptions.PUSHER_APP_ID, _pusherOptions.PUSHER_KEY, _pusherOptions.PUSHER_SECRET);
            var auth   = pusher.Authenticate(channel_name, socket_id);
            var json   = auth.ToJson();

            return(new ContentResult {
                Content = json, ContentType = "application/json"
            });
        }
コード例 #13
0
        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));
        }
コード例 #14
0
        public async Task <IActionResult> Pusher([FromForm] string channel_name, [FromForm] string socket_id)
        {
            var pusher = new Pusher("924297", "b764a51bdf1cdf760ad6", "9250a463d6d5efea534d", new PusherOptions
            {
                Cluster = "us2"
            });
            var auth = pusher.Authenticate(channel_name, socket_id, new PresenceChannelData()).ToJson();

            return(new ContentResult {
                Content = auth, ContentType = "application/json"
            });
        }
コード例 #15
0
 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" };
 }
コード例 #16
0
        public IActionResult ChannelAuth(string channel_name, string socket_id)
        {
            int group_id;

            if (!User.Identity.IsAuthenticated)
            {
                return(new ContentResult {
                    Content = "Access forbidden", ContentType = "application/json"
                });
            }

            try
            {
                group_id = Int32.Parse(channel_name.Replace("private-", ""));
            }
            catch (FormatException e)
            {
                return(Json(new { Content = e.Message }));
            }

            var IsInChannel = _context.UserGroups
                              .Where(gb => gb.GroupId == group_id &&
                                     gb.UserName == _userManager.GetUserName(User))
                              .Count();

            if (IsInChannel > 0)
            {
                var options = new PusherOptions
                {
                    Cluster   = "PUSHER_APP_CLUSTER",
                    Encrypted = true
                };
                var pusher = new Pusher(
                    "671063",
                    "016b0a9c29ee69a1c1e0",
                    "67c82f7eec24bfba97ed",
                    options
                    );

                var auth = pusher.Authenticate(channel_name, socket_id).ToJson();
                return(new ContentResult {
                    Content = auth, ContentType = "application/json"
                });
            }
            return(new ContentResult {
                Content = "Access forbidden", ContentType = "application/json"
            });
        }
コード例 #17
0
        public IActionResult ChannelAuth(string channel_name, string socket_id)
        {
            int group_id;

            if (!User.Identity.IsAuthenticated)
            {
                return(new ContentResult {
                    Content = "Access forbidden", ContentType = "application/json"
                });
            }

            try
            {
                group_id = Int32.Parse(channel_name.Replace("private-", ""));
            }
            catch (FormatException e)
            {
                return(Json(new { Content = e.Message }));
            }

            var IsInChannel = _context.UserGroup
                              .Where(gb => gb.GroupId == group_id &&
                                     gb.UserName == _userManager.GetUserName(User))
                              .Count();

            if (IsInChannel > 0)
            {
                var options = new PusherOptions
                {
                    Cluster   = "us2",
                    Encrypted = true
                };
                var pusher = new Pusher(
                    "620160",
                    "87c7848afc7bbeaf081c",
                    "7e6906f867f9e88df0d2",
                    options
                    );

                var auth = pusher.Authenticate(channel_name, socket_id).ToJson();
                return(new ContentResult {
                    Content = auth, ContentType = "application/json"
                });
            }
            return(new ContentResult {
                Content = "Access forbidden", ContentType = "application/json"
            });
        }
コード例 #18
0
        public IActionResult ChannelAuth(string channel_name, string socket_id)
        {
            int group_id;

            if (!User.Identity.IsAuthenticated)
            {
                return(new ContentResult {
                    Content = "Access forbidden", ContentType = "application/json"
                });
            }

            try
            {
                group_id = Int32.Parse(channel_name.Replace("private-", ""));
            }
            catch (FormatException e)
            {
                return(Json(new { Content = e.Message }));
            }

            int IsInChannel = _context.UsersGroups
                              .Count(gb => gb.GroupId == group_id &&
                                     gb.UserName == _userManager.GetUserName(User));

            if (IsInChannel > 0)
            {
                var options = new PusherOptions
                {
                    Cluster   = _configuration["PUSHER_APP_CLUSTER"],
                    Encrypted = true
                };
                var pusher = new Pusher(
                    _configuration["PUSHER_APP_ID"],
                    _configuration["PUSHER_APP_KEY"],
                    _configuration["PUSHER_APP_SECRET"],
                    options
                    );

                var auth = pusher.Authenticate(channel_name, socket_id).ToJson();
                return(new ContentResult {
                    Content = auth, ContentType = "application/json"
                });
            }

            return(new ContentResult {
                Content = "Access forbidden", ContentType = "application/json"
            });
        }
コード例 #19
0
        public IActionResult ChannelAuth(string channel_name, string socket_id)
        {
            int group_id;

            if (!User.Identity.IsAuthenticated)
            {
                return(new ContentResult {
                    Content = "Access forbidden", ContentType = "application/json"
                });
            }

            try
            {
                group_id = Int32.Parse(channel_name.Replace("private-", ""));
            }
            catch (FormatException e)
            {
                return(Json(new { Content = e.Message }));
            }

            var IsInChannel = _context.UserGroup
                              .Where(gb => gb.GroupId == group_id &&
                                     gb.UserName == _userManager.GetUserName(User))
                              .Count();

            if (IsInChannel > 0)
            {
                var options = new PusherOptions
                {
                    Cluster   = "eu",
                    Encrypted = true
                };
                var pusher = new Pusher(
                    "733746",
                    "2197134b840b0f51ef40",
                    "6d3361985f6d36d29def",
                    options
                    );

                var auth = pusher.Authenticate(channel_name, socket_id).ToJson();
                return(new ContentResult {
                    Content = auth, ContentType = "application/json"
                });
            }
            return(new ContentResult {
                Content = "Access forbidden", ContentType = "application/json"
            });
        }
コード例 #20
0
        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"
            });
        }
コード例 #21
0
ファイル: AuthController.cs プロジェクト: Oleks-Y/ChatOne.Api
        public IActionResult AuthForChannel(int currUserId, string channel_name, string socket_id)
        {
            var user = _unitOfWork.Users.Get(currUserId);

            var options = new PusherOptions();

            options.Cluster = "eu";
            var pusher = new Pusher(
                "1041895",
                "0a54a9ffa32985979dd5",
                "ff562a59173102085807",
                options
                );

            var auth = pusher.Authenticate(channel_name, socket_id);

            return(Json(auth));
        }
コード例 #22
0
        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);
        }
コード例 #23
0
ファイル: PusherController.cs プロジェクト: fawad1997/TechIn
        public async Task <JsonResult> Auth(string channel_name, string socket_id)
        {
            var user = await _userManager.GetCurrentUser(HttpContext);

            var userId  = Int32.Parse(user.Id);
            var options = new PusherOptions
            {
                Cluster   = "us2",
                Encrypted = true
            };

            var pusher = new Pusher("687183", "32faf5983beaa45f0d69", "f63fefed03842ede52f9", options);

            if (channel_name.IndexOf(userId.ToString()) == -1)
            {
                return(Json(
                           new { status = "error", message = "User cannot join channel" }
                           ));
            }
            var auth = pusher.Authenticate(channel_name, socket_id);

            return(Json(auth));
        }
コード例 #24
0
        public JsonResult ChannelAuth(string channel_name, string socket_id)
        {
            int group_id;

            if (!User.Identity.IsAuthenticated)
            {
                return(Json(new { Content = "Access forbidden" }));
            }

            try
            {
                group_id = Int32.Parse(channel_name.Replace("private-", ""));
            }
            catch (FormatException e)
            {
                return(Json(new  { Content = e.Message }));
            }

            var IsInChannel = _context.UserGroup.Where(
                gb => gb.GroupId == group_id &&
                gb.UserName == _userManager.GetUserName(User)
                ).Count();

            if (IsInChannel > 0)
            {
                var pusher = new Pusher(
                    "PUSHER_APP_ID",
                    "PUSHER_APP_KEY",
                    "PUSHER_APP_SECRET"
                    );

                var auth = pusher.Authenticate(channel_name, socket_id).ToJson();
                return(Json(new { Content = auth }));
            }

            return(Json(new { Content = "Access forbidden" }));
        }
コード例 #25
0
        public JsonResult AuthForChannel([FromBody] AuthForChannelRequest data)
        {
            var currentUser = m_context.Users.FirstOrDefault(u => u.name == "pepe");

            var options = new PusherOptions();

            options.Cluster = "us2";

            var pusher = new Pusher(
                "959730",
                "04016b8df0172af7d6fd",
                "0040d7c958bc43bc307a", options);

            if (data.channel_name.IndexOf(currentUser.id.ToString()) == -1)
            {
                return(new JsonResult(
                           new { status = "error", message = "User cannot join channel" }
                           ));
            }

            var auth = pusher.Authenticate(data.channel_name, data.socket_id);

            return(new JsonResult(auth));
        }