Ejemplo n.º 1
0
        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);
            };
        }
Ejemplo n.º 2
0
        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 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);
        }
Ejemplo n.º 4
0
        public string AuthenticateListener(string channelId, string socketId)
        {
            var authenticationData = _pusher.Authenticate(channelId, socketId);

            return(authenticationData.auth);
        }