This repository has been archived on 2024-11-11 . You can view files and clone it, but cannot push or open issues or pull requests.
Bradley Olson
f62a93c9d2
added option of success or fail callbacks. Needed to still allow users access to sockets even if they weren't logged in, but needed specific data if they were.
Access Passport.js user information from socket.io connection.
Installation
npm install passport.socketio
Usage
//configure passport and express
var socketIo = require("socket.io"),
passportSocketIo = require("passport.socketio");
var sio = socketIo.listen(webServer);
sio.set("authorization", passportSocketIo.authorize({
sessionKey: 'express.sid', //the cookie where express (or connect) stores its session id.
sessionStore: mySessionStore, //the session store that express uses
sessionSecret: "my session secret" //the session secret to parse the cookie
}));
sio.sockets.on("connection", function(socket){
console.log("user connected: ", socket.handshake.user.name);
//filter sockets by user...
var userGender = socket.handshake.user.gender,
opposite = userGender === "male" ? "female" : "male";
passportSocketIo.filterSocketsByUser(sio, function (user) {
return user.gender === opposite;
}).forEach(function(s){
s.send("a " + userGender + " has arrived!");
});
});
License
MIT - José F. Romaniello 2012.
Description
Authenticate socket.io incoming connections with JWTs.
https://www.npmjs.com/package/@thream/socketio-jwt
Readme
3.9 MiB
Languages
TypeScript
98.9%
Shell
1.1%