fix #6 use same parameters than express.session
This commit is contained in:
parent
a1e46b1fbd
commit
66dd460070
10
README.md
10
README.md
@ -21,10 +21,14 @@ Usage
|
|||||||
|
|
||||||
var sio = socketIo.listen(webServer);
|
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({
|
sio.set("authorization", passportSocketIo.authorize({
|
||||||
sessionKey: 'express.sid', //the cookie where express (or connect) stores its session id.
|
key: 'express.sid', //the cookie where express (or connect) stores its session id.
|
||||||
sessionStore: mySessionStore, //the session store that express uses
|
secret: 'my session secret', //the session secret to parse the cookie
|
||||||
sessionSecret: "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
|
fail: function(data, accept) { // *optional* callbacks on success or fail
|
||||||
accept(null, false); // second param takes boolean on whether or not to allow handshake
|
accept(null, false); // second param takes boolean on whether or not to allow handshake
|
||||||
},
|
},
|
||||||
|
16
lib/index.js
16
lib/index.js
@ -3,16 +3,16 @@ var connectUtils = require('connect').utils,
|
|||||||
xtend = require('xtend');
|
xtend = require('xtend');
|
||||||
|
|
||||||
function authorize(options) {
|
function authorize(options) {
|
||||||
var auth = {
|
var defaults = {
|
||||||
passport: require('passport'),
|
passport: require('passport'),
|
||||||
sessionKey: 'express.sid',
|
key: 'express.sid',
|
||||||
sessionSecret: null,
|
secret: null,
|
||||||
sessionStore: null,
|
store: null,
|
||||||
success: null,
|
success: null,
|
||||||
fail: null
|
fail: null
|
||||||
};
|
};
|
||||||
|
|
||||||
xtend( auth, options );
|
var auth = xtend({}, defaults, options );
|
||||||
|
|
||||||
auth.userProperty = auth.passport._userProperty || 'user';
|
auth.userProperty = auth.passport._userProperty || 'user';
|
||||||
|
|
||||||
@ -23,11 +23,11 @@ function authorize(options) {
|
|||||||
|
|
||||||
var parsedCookie = cookie.parse(data.headers.cookie);
|
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) {
|
if (err) {
|
||||||
return accept('Error in session store.', false);
|
return accept('Error in session store.', false);
|
||||||
} else if (!session) {
|
} else if (!session) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "passport.socketio",
|
"name": "passport.socketio",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"description": "access passport.js authenticated user information from socket.io",
|
"description": "access passport.js authenticated user information from socket.io",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
@ -8,8 +8,13 @@ var socketIo = require('socket.io'),
|
|||||||
passportSocketIo = require('../../lib');
|
passportSocketIo = require('../../lib');
|
||||||
|
|
||||||
var sessionStore = new connect.session.MemoryStore(),
|
var sessionStore = new connect.session.MemoryStore(),
|
||||||
cookieSecret = 'asdasdsdas1312312',
|
sessionSecret = 'asdasdsdas1312312',
|
||||||
sessionKey = 'test-session-key';
|
sessionKey = 'test-session-key',
|
||||||
|
sessionOptions = {
|
||||||
|
store: sessionStore,
|
||||||
|
key: sessionKey,
|
||||||
|
secret: sessionSecret
|
||||||
|
};
|
||||||
|
|
||||||
var server;
|
var server;
|
||||||
|
|
||||||
@ -24,15 +29,12 @@ exports.start = function (options, callback) {
|
|||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
app.configure(function(){
|
app.configure(function(){
|
||||||
app.use(express.cookieParser(cookieSecret));
|
app.use(express.cookieParser());
|
||||||
|
|
||||||
app.use(express.bodyParser());
|
app.use(express.bodyParser());
|
||||||
app.use(express.methodOverride());
|
app.use(express.methodOverride());
|
||||||
|
|
||||||
app.use(express.session({
|
app.use(express.session(sessionOptions));
|
||||||
store: sessionStore,
|
|
||||||
key: sessionKey
|
|
||||||
}));
|
|
||||||
|
|
||||||
app.use(passport.initialize());
|
app.use(passport.initialize());
|
||||||
app.use(passport.session());
|
app.use(passport.session());
|
||||||
@ -55,11 +57,7 @@ exports.start = function (options, callback) {
|
|||||||
|
|
||||||
var sio = socketIo.listen(server);
|
var sio = socketIo.listen(server);
|
||||||
sio.configure(function(){
|
sio.configure(function(){
|
||||||
this.set('authorization', passportSocketIo.authorize(xtend({
|
this.set('authorization', passportSocketIo.authorize(xtend(sessionOptions, options)));
|
||||||
sessionKey: sessionKey,
|
|
||||||
sessionStore: sessionStore,
|
|
||||||
sessionSecret: cookieSecret
|
|
||||||
}, options)));
|
|
||||||
|
|
||||||
this.set('log level', 0);
|
this.set('log level', 0);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user