2
1
mirror of https://github.com/Thream/socketio-jwt.git synced 2024-07-21 09:38:31 +02:00

fix #6 use same parameters than express.session

This commit is contained in:
Jose F. Romaniello 2013-02-05 19:15:04 -03:00
parent a1e46b1fbd
commit 66dd460070
4 changed files with 27 additions and 25 deletions

View File

@ -21,10 +21,14 @@ Usage
var sio = socketIo.listen(webServer);
//except for the optional fail and success the parameter object has the
//same attribute than the session middleware http://www.senchalabs.org/connect/middleware-session.html
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
key: 'express.sid', //the cookie where express (or connect) stores its session id.
secret: 'my session secret', //the session secret to parse the cookie
store: mySessionStore, //the session store that express uses
fail: function(data, accept) { // *optional* callbacks on success or fail
accept(null, false); // second param takes boolean on whether or not to allow handshake
},

View File

@ -3,17 +3,17 @@ var connectUtils = require('connect').utils,
xtend = require('xtend');
function authorize(options) {
var auth = {
var defaults = {
passport: require('passport'),
sessionKey: 'express.sid',
sessionSecret: null,
sessionStore: null,
key: 'express.sid',
secret: null,
store: null,
success: null,
fail: null
};
xtend( auth, options );
var auth = xtend({}, defaults, options );
auth.userProperty = auth.passport._userProperty || 'user';
return function(data, accept){
@ -23,11 +23,11 @@ function authorize(options) {
var parsedCookie = cookie.parse(data.headers.cookie);
data.cookie = connectUtils.parseSignedCookies(parsedCookie, auth.sessionSecret);
data.cookie = connectUtils.parseSignedCookies(parsedCookie, auth.secret);
data.sessionID = data.cookie[ auth.sessionKey ];
data.sessionID = data.cookie[ auth.key ];
auth.sessionStore.get(data.sessionID, function(err, session){
auth.store.get(data.sessionID, function(err, session){
if (err) {
return accept('Error in session store.', false);
} else if (!session) {

View File

@ -1,6 +1,6 @@
{
"name": "passport.socketio",
"version": "0.0.4",
"version": "0.0.5",
"description": "access passport.js authenticated user information from socket.io",
"main": "lib/index.js",
"keywords": [

View File

@ -8,8 +8,13 @@ var socketIo = require('socket.io'),
passportSocketIo = require('../../lib');
var sessionStore = new connect.session.MemoryStore(),
cookieSecret = 'asdasdsdas1312312',
sessionKey = 'test-session-key';
sessionSecret = 'asdasdsdas1312312',
sessionKey = 'test-session-key',
sessionOptions = {
store: sessionStore,
key: sessionKey,
secret: sessionSecret
};
var server;
@ -24,15 +29,12 @@ exports.start = function (options, callback) {
var app = express();
app.configure(function(){
app.use(express.cookieParser(cookieSecret));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.session({
store: sessionStore,
key: sessionKey
}));
app.use(express.session(sessionOptions));
app.use(passport.initialize());
app.use(passport.session());
@ -55,11 +57,7 @@ exports.start = function (options, callback) {
var sio = socketIo.listen(server);
sio.configure(function(){
this.set('authorization', passportSocketIo.authorize(xtend({
sessionKey: sessionKey,
sessionStore: sessionStore,
sessionSecret: cookieSecret
}, options)));
this.set('authorization', passportSocketIo.authorize(xtend(sessionOptions, options)));
this.set('log level', 0);