remove connect and cookie dependency
This commit is contained in:
parent
9fea831500
commit
04ea36fdd3
@ -26,6 +26,7 @@ Usage
|
||||
//same attribute than the session middleware http://www.senchalabs.org/connect/middleware-session.html
|
||||
|
||||
sio.set("authorization", passportSocketIo.authorize({
|
||||
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
|
||||
|
27
lib/index.js
27
lib/index.js
@ -1,6 +1,19 @@
|
||||
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 = {
|
||||
@ -16,14 +29,16 @@ function authorize(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