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;
            };
        }
Example #2
0
 /// <summary>
 /// Authenticates the subscription request for a presence channel.
 /// </summary>
 /// <param name="channelName">Name of the channel to be authenticated.</param>
 /// <param name="socketId">The socket id which uniquely identifies the connection attempting to subscribe to the channel.</param>
 /// <param name="presenceData">Information about the user subscribing to the presence channel.</param>
 /// <exception cref="ArgumentNullException">If <paramref name="presenceData"/> is null</exception>
 /// <returns>Authentication data where the required authentication token can be accessed via <see cref="IAuthenticationData.auth"/></returns>
 public IAuthenticationData Authenticate(string channelName, string socketId, PresenceChannelData presenceData)
 {
     if (presenceData == null)
     {
         throw new ArgumentNullException("presenceData");
     }
     return(new AuthenticationData(this._appKey, this._appSecret, channelName, socketId, presenceData));
 }
Example #3
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" };
 }
Example #4
0
 public AuthenticationData(string appKey, string appSecret, string channelName, string socketId, PresenceChannelData presenceData) :
     this(appKey, appSecret, channelName, socketId)
 {
     _presenceData = presenceData;
 }
 public AuthenticationData(string appKey, string appSecret, string channelName, string socketId, PresenceChannelData presenceData)
     : this(appKey, appSecret, channelName, socketId)
 {
     _presenceData = presenceData;
 }
Example #6
0
 /// <summary>
 /// Authenticates the specified channel name.
 /// </summary>
 /// <param name="channelName">Name of the channel.</param>
 /// <param name="socketId">The socket id.</param>
 /// <param name="presenceData">The presence data.</param>
 /// <returns></returns>
 public IAuthenticationData Authenticate(string channelName, string socketId, PresenceChannelData presenceData)
 {
     return(new AuthenticationData(this._appKey, this._appSecret, channelName, socketId, presenceData));
 }