facundoolano/socketio-auth

unable to use passport authenticate method with socket io

Closed this issue · 1 comments

Hello,

i am trying to use passport authentication (bearer) within authenticate method but passport authenticate method not called up.

Also is it possible to send extra headers.
http://stackoverflow.com/questions/23406163/socket-io-client-how-to-set-request-header-when-making-connection

can we use that header to send token and use passport authenticate bearer method directly.

require('socketio-auth')(io, {
  authenticate: function (socket, data, callback) {
    //get token sent by the client 
   // var token = data.token;
   console.log(passport);
    try{
         **passport.authenticate('bearer',{session: false }, function() {
   console.log("here in callback");   
  });**
   // passport.authenticate('bearer', { session: false });
    }catch(e){console.log(e);}

    console.log("in socket authenticate");
  }
});

AFAIK passport.authenticate returns a middleware function (one that takes req, res and next). That doesn't make much sense in the context of socket io authentication.

This module was conceived because socket.io did not support headers at the time, but if it does know it's probably best to use that directly.