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
|
//same attribute than the session middleware http://www.senchalabs.org/connect/middleware-session.html
|
||||||
|
|
||||||
sio.set("authorization", passportSocketIo.authorize({
|
sio.set("authorization", passportSocketIo.authorize({
|
||||||
|
cookieParser: express.cookieParser, //or connect.cookieParser
|
||||||
key: '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.
|
||||||
secret: 'my session secret', //the session secret to parse the cookie
|
secret: 'my session secret', //the session secret to parse the cookie
|
||||||
store: mySessionStore, //the session store that express uses
|
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,
|
var xtend = require('xtend');
|
||||||
cookie = require('cookie'),
|
|
||||||
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) {
|
function authorize(options) {
|
||||||
var defaults = {
|
var defaults = {
|
||||||
@ -16,14 +29,16 @@ function authorize(options) {
|
|||||||
|
|
||||||
auth.userProperty = auth.passport._userProperty || 'user';
|
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){
|
return function(data, accept){
|
||||||
if (!data.headers.cookie) {
|
if (!data.headers.cookie) {
|
||||||
return accept(null, false);
|
return accept(null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var parsedCookie = cookie.parse(data.headers.cookie);
|
data.cookie = parseCookie(auth, data.headers.cookie);
|
||||||
|
|
||||||
data.cookie = connectUtils.parseSignedCookies(parsedCookie, auth.secret);
|
|
||||||
|
|
||||||
data.sessionID = data.cookie[ auth.key ];
|
data.sessionID = data.cookie[ auth.key ];
|
||||||
|
|
||||||
|
@ -22,8 +22,6 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"passport": "~0.1.16",
|
"passport": "~0.1.16",
|
||||||
"connect": "2.7.5",
|
|
||||||
"cookie": "0.0.5",
|
|
||||||
"request": "~2.19.0",
|
"request": "~2.19.0",
|
||||||
"xtend": "~2.0.3"
|
"xtend": "~2.0.3"
|
||||||
},
|
},
|
||||||
@ -34,6 +32,7 @@
|
|||||||
"socket.io": "~0.9.14",
|
"socket.io": "~0.9.14",
|
||||||
"passport-local": "~0.1.6",
|
"passport-local": "~0.1.6",
|
||||||
"xmlhttprequest": "~1.5.0",
|
"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'){
|
if(typeof options == 'function'){
|
||||||
callback = options;
|
callback = options;
|
||||||
options = {};
|
options = {
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
options.cookieParser = express.cookieParser;
|
||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
app.configure(function(){
|
app.configure(function(){
|
||||||
|
Reference in New Issue
Block a user