Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


fix bug: use passport provided in options hash #55

wants to merge 3 commits into from

4 participants


it took me several hours to figure this out: I was using passport 0.1.17, because passport-local forced me to stick with this version. Then, passport.socketio was loading passport 0.2.0, even though I had provided passport as a parameter to the options hash. It turns out that the passport: require('passport') already loads version 0.2.0 and this version does not go away.
The wrong lib caused problems, because the signature of serializeUser changed between 0.1.17 and 0.2.0.


i always thought that's exactly what xtend(a,b) does. and this does the trick?


ok, you are right: I have created an isolated test where I do require and use xtend in the same way you do. Here, the passport form the options hash was used. And the default one was not used.

When I use passport 0.2.0, everything works fine.

When I use passport 0.1.17, I get this error:

        throw err;
TypeError: object is not a function
    at pass (/my/project/node_modules/passport/lib/passport/index.js:281:14)
    at Passport.serializeUser (/my/project/node_modules/passport/lib/passport/index.js:283:5)
    at IncomingMessage.req.login.req.logIn (/my/project/node_modules/passport.socketio/node_modules/passport/lib/http/request.js:48:29)
    at Context.delegate.success (/my/project/node_modules/passport/lib/passport/middleware/authenticate.js:194:13)
    at Context.actions.success (/my/project/node_modules/passport/lib/passport/context/http/actions.js:21:25)
    at verified (/my/project/node_modules/passport-local/lib/passport-local/strategy.js:83:10)
    at Promise.<anonymous> (/my/project/lib/
    at Promise.<anonymous> (/my/project/node_modules/mongoose/node_modules/mpromise/lib/promise.js:162:8)
    at Promise.EventEmitter.emit (events.js:95:17)
    at Promise.emit (/my/project/node_modules/mongoose/node_modules/mpromise/lib/promise.js:79:38)

as you can see, we have passport.socketio/node_modules/passport/lib/http/request.js and passport/lib/passport/index.js which do not go together well.

The way I am calling this is like this:

passport      = require('passport')
passportSocketIo = require("passport.socketio")
io.set "authorization", passportSocketIo.authorize(
  cookieParser: express.cookieParser
  secret: secret
  store: redisStore
  passport: passport
  success: onAuthorizeSuccess
  fails: onAuthorizeFail

this is my packages.json

  "name": "meeting-planner",
  "version": "0.0.1",
  "private": true,
  "engines": {
    "node": "0.10.x",
    "npm": "1.2.x"
  "dependencies": {
    "async": ">=0.2.6",
    "coffee-script": "1.5.0",
    "cookie-signature": "1.0.1",
    "connect-assets": "2.4.0",
    "connect-redis": "1.4.6",
    "colors": "*",
    "express": "~3.4.8",
    "express-resource": "1.0.0",
    "jade": ">= 0.28.2",
    "mongoose": "3.6.13",
    "nodemailer": "0.5.2",
    "passport": "0.1.17",
    "passport-local": "0.1.6",
    "": "~0.9.13",
    "": "0.9.11",
    "underscore": ">=1.4.4",
    "winston": "0.6.x",
    "heroku-redis-client": "~0.3.3",
    "karma-ng-scenario": "~0.1.0",
    "amazon-s3-url-signer": "~0.0.7",
    "knox": "~0.8.9",
    "xtend": "~2.0.3",
    "passport.socketio": "~3.0.0"

And strangely enough, everything works when I change the code as in my pull request.


I just wanted to jump in and say that I'm experiencing a similar issue:

I have passport 0.2.0 set up in my app. When I require it and set up my serializeUser and deserializeUser methods, passport.socketio seems to use its own passport module which does not know my custom serializer methods.

When I require the passport module from within passport.socketio everything seems to work.


@sebastianhoitz That's weird because this module depends on 0.2.0 as well. You might want to send the passport reference in the function:

  passport: passport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 1 deletion.
  1. +4 −1 lib/index.js
5 lib/index.js
@@ -17,7 +17,6 @@ function parseCookie(auth, cookieHeader) {
function authorize(options) {
var defaults = {
- passport: require('passport'),
key: 'connect.sid',
secret: null,
store: null,
@@ -27,6 +26,10 @@ function authorize(options) {
var auth = xtend(defaults, options);
+ if (!auth.passport){
+ auth.passport = require('passport'); //not added in defaults, because that would already load the other passport.
+ }
auth.userProperty = auth.passport._userProperty || 'user';
if (!auth.cookieParser) {
Something went wrong with that request. Please try again.