title: Session issues with Passport.js and Restify
body: <p>I'm trying to develop a simple proof of concept that uses Passport's Google authentication strategy with Restify and Bookshelf.js.  I would like this simple app to enable me to resolve a /sessions/google route (which invokes Google authentication) and redirect to /sessions/googleReturn upon successful authentication.  For this simple proof of concept, please assume that the table that corresponds to the User model contains a record for the user that is authenticating.</p>
  
  <p>Below is the code that I'm currently experimenting with.  Currently, this code results in an endless redirect loop after authenticating.  If I remove the 'passport.authenticate('google', { failureRedirect: '/' })' line within the /sessions/googleReturn route, /sessions/googleReturn resolves however req.user returns an empty object.  I'm guessing that I'm not initializing the session or binding the session to passport correctly.  The console.log output inside the passport methods appears to be suppressed, which is making this difficult to debug.  If I substitute Restify/client-sessions with express/express-session, my proof of concept works. What am I doing wrong?  Thanks in advance.</p>
  
  <pre><code>var restify = require('restify');
  var sessions = require('client-sessions');
  var passport = require('passport');
  var GoogleStrategy = require('passport-google').Strategy;
  var User = require('./models/user'); // Bookshelf model
  
  var server = restify.createServer({ name: 'test-server' });
  
  server
    .use(sessions({
      cookieName: 'user',
      secret: 'topsecret',
      duration: 365 * 24 * 60 * 60 * 1000}))
    .use(passport.initialize())
    .use(passport.session());
  
  passport.serializeUser(function(user, done) {
    console.log('serialize user:', user);
    done(null, user.id);
  });
  
  passport.deserializeUser(function(id, done) {
    console.log('deserialize user:', id);
    new User({ id: id }).fetch({require: true}).then(function(user) {
      done(null, user);
    }).catch(function(err) {
      done(err, null);
    });
  });
  
  passport.use(
    new GoogleStrategy({
      returnURL: 'http://localhost:3000/sessions/googleReturn',
      realm: 'http://localhost:3000'
    },
    function(identifier, profile, done) {
      console.log('Hello from the verify callback', identifier, profile);
      new User({ email: profile.emails[0].value }).fetch({require: true}).then(function(user) {
        done(null, user);
      }).catch(function(err) {
        done(err, null);
      });
    }
  ));
  
  server.listen(3000, function () {
    console.log('%s listening at %s', server.name, server.url);
  });
  
  server.get('/', function(req, res, next) {
    res.send(200, 'Hello from root route.');
    return next();
  });
  
  server.get(
    '/sessions/google',
    passport.authenticate('google')
  );
  
  server.get(
    '/sessions/googleReturn',
    passport.authenticate('google', { failureRedirect: '/' }),
    function(req, res, next) {
      console.log('Session user data?', req.user);
      res.send(200, 'Hello from Google auth return route.');
      return next();
    }
  );
  </code></pre>