remove connect and cookie dependency
This commit is contained in:
parent
9fea831500
commit
04ea36fdd3
11
README.md
11
README.md
@ -26,11 +26,12 @@ Usage
|
||||
//same attribute than the session middleware http://www.senchalabs.org/connect/middleware-session.html
|
||||
|
||||
sio.set("authorization", passportSocketIo.authorize({
|
||||
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
|
||||
cookieParser: express.cookieParser, //or connect.cookieParser
|
||||
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
|
||||
},
|
||||
success: function(data, accept) {
|
||||
accept(null, true);
|
||||
|
39
lib/index.js
39
lib/index.js
@ -1,29 +1,44 @@
|
||||
var connectUtils = require('connect').utils,
|
||||
cookie = require('cookie'),
|
||||
xtend = require('xtend');
|
||||
var xtend = require('xtend');
|
||||
|
||||
function parseCookie(auth, cookieHeader) {
|
||||
var cookieParser = auth.cookieParser(auth.secret);
|
||||
var req = {
|
||||
headers:{
|
||||
cookie: cookieHeader
|
||||
}
|
||||
};
|
||||
var result;
|
||||
cookieParser(req, {}, function (err) {
|
||||
if (err) throw err;
|
||||
result = req.signedCookies;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
function authorize(options) {
|
||||
var defaults = {
|
||||
passport: require('passport'),
|
||||
key: 'connect.sid',
|
||||
secret: null,
|
||||
store: null,
|
||||
success: null,
|
||||
fail: null
|
||||
passport: require('passport'),
|
||||
key: 'connect.sid',
|
||||
secret: null,
|
||||
store: null,
|
||||
success: null,
|
||||
fail: null
|
||||
};
|
||||
|
||||
var auth = xtend({}, defaults, options );
|
||||
|
||||
auth.userProperty = auth.passport._userProperty || 'user';
|
||||
|
||||
if (typeof auth.cookieParser === 'undefined' || !auth.cookieParser) {
|
||||
throw new Error('cookieParser is required use connect.cookieParser or express.cookieParser');
|
||||
}
|
||||
|
||||
return function(data, accept){
|
||||
if (!data.headers.cookie) {
|
||||
return accept(null, false);
|
||||
}
|
||||
|
||||
var parsedCookie = cookie.parse(data.headers.cookie);
|
||||
|
||||
data.cookie = connectUtils.parseSignedCookies(parsedCookie, auth.secret);
|
||||
data.cookie = parseCookie(auth, data.headers.cookie);
|
||||
|
||||
data.sessionID = data.cookie[ auth.key ];
|
||||
|
||||
|
@ -22,8 +22,6 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"passport": "~0.1.16",
|
||||
"connect": "2.7.5",
|
||||
"cookie": "0.0.5",
|
||||
"request": "~2.19.0",
|
||||
"xtend": "~2.0.3"
|
||||
},
|
||||
@ -34,6 +32,7 @@
|
||||
"socket.io": "~0.9.14",
|
||||
"passport-local": "~0.1.6",
|
||||
"xmlhttprequest": "~1.5.0",
|
||||
"socket.io-client": "git+https://github.com/jfromaniello/socket.io-client.git"
|
||||
"socket.io-client": "git+https://github.com/jfromaniello/socket.io-client.git",
|
||||
"connect": "~2.7.11"
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,10 @@ exports.start = function (options, callback) {
|
||||
|
||||
if(typeof options == 'function'){
|
||||
callback = options;
|
||||
options = {};
|
||||
options = {
|
||||
};
|
||||
}
|
||||
options.cookieParser = express.cookieParser;
|
||||
|
||||
var app = express();
|
||||
app.configure(function(){
|
||||
|
Reference in New Issue
Block a user