“Authentification Socket.Io” Réponses codées

Authentification Socket.Io

req.session.regenerate...
res.send({rediskey: req.sessionID});
SAMER SAEID

Authentification Socket.Io

//in io.on('connection')
io.on('connection', function(client) {
  client.on('message', function(message) {

    if(message.rediskey) {
      //fetch session info from redis
      redisclient.get(message.rediskey, function(e, c) {
        client.user_logged_in = c.username;
      });
    }

  });
});
SAMER SAEID

Authentification Socket.Io

//store the key in a cookie
SetCookie('rediskey', <%= rediskey %>); //http://msdn.microsoft.com/en-us/library/ms533693(v=vs.85).aspx

//then when socket is connected, fetch the rediskey from the document.cookie and send it back to server
var socket = new io.Socket();

socket.on('connect', function() {
  var rediskey = GetCookie('rediskey'); //http://msdn.microsoft.com/en-us/library/ms533693(v=vs.85).aspx
  socket.send({rediskey: rediskey});
});
SAMER SAEID

Réponses similaires à “Authentification Socket.Io”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code