title: Error: passport.initialize() middleware not in use what order to make calls?
body: <p>I have the follow - Generated initially by the Visual Studio Node Tools, uses Express and Jade as the client </p>
  
  <pre><code>/**
   * Module dependencies.
   */
  
  var express         = require('express');
  var fs              = require('fs');
  var routes          = require('./routes');
  var user            = require('./routes/user');
  var http            = require('http');
  var https           = require('https');
  var path            = require('path');
  var passport        = require('passport');
  var googleStrategy  = require('passport-google-oauth').OAuth2Strategy;
  var loginHandler    = require('./routes/Login.js');
  var auth            = require('./config/auth.js');
  var googleSupport   = require('./googleSupport.js');
  
  var googleAuthority = auth.googleAuth;
  var googleScopes = '';
  
  
  // retrieve google scopes
  googleScopes = googleSupport.discoverServiceScopes(auth.googleAuth);
  
  // set up passport
  passport.serializeUser(function (user,done) {
      done(null, user);
  });
  
  passport.deserializeUser(function (obj, done) {
      done(null, obj);
  });
  
  passport.use(new googleStrategy({
      clientID: googleAuthority.clientId,
      clientSecret: googleAuthority.clientSecret,
      callbackURL: googleAuthority.callbackUrl
  },
  function (accessToken, refreshToken, profile, done) {
      return done(null, profile);
  }
  ));
  var request = require('request');
  
  var app = express();
  
  // all environments
  app.set('port', process.env.PORT || 3000);
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.json());
  app.use(express.urlencoded());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(require('stylus').middleware(path.join(__dirname, 'public')));
  app.use(express.static(path.join(__dirname, 'public')));
  
  // development only
  if ('development' == app.get('env')) {
      app.use(express.errorHandler());
  }
  
  console.log('extracting service scopes');
  
  app.get(passport.initialize());
  app.get(passport.session());
  
  app.get('/', routes.index);
  app.get('/index', routes.index);
  
  // google login support
  
  // go to login page.
  app.get('/googleLogin', passport.authenticate('google', { scope: [googleScopes] }), 
      function (req, res) {
          res.redirect('/');
      }
  );
  
  app.get('/AuthorizeGoogle', passport.authenticate('google', { failureRedirect: '/'}), 
      function (req, res) { 
          res.redirect('/');
      });
  
  
  http.createServer(app).listen(app.get('port'), function () {
      console.log('Express server listening on port ' + app.get('port'));
  });
  </code></pre>
  
  <p>The thing is when it validates the user I get the following</p>
  
  <pre><code>500 Error: passport.initialize() middleware not in use
  at IncomingMessage.req.login.req.logIn (C:\Node\YourLivesN\YourLivesN\node_modules\passport\lib\http\request.js:44:34)
  at Strategy.module.exports.strategy.success (C:\Node\YourLivesN\YourLivesN\node_modules\passport\lib\middleware\authenticate.js:228:13)
  at verified (C:\Node\YourLivesN\YourLivesN\node_modules\passport-oauth\node_modules\passport-oauth2\lib\strategy.js:179:18)
  at Strategy._verify (C:\Node\YourLivesN\YourLivesN\app.js:41:12)
  at C:\Node\YourLivesN\YourLivesN\node_modules\passport-oauth\node_modules\passport-oauth2\lib\strategy.js:195:22
  at C:\Node\YourLivesN\YourLivesN\node_modules\passport-google-oauth\lib\passport-google-oauth\oauth2.js:115:7
  at passBackControl (C:\Node\YourLivesN\YourLivesN\node_modules\passport-oauth\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:125:9)
  at IncomingMessage. (C:\Node\YourLivesN\YourLivesN\node_modules\passport-oauth\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:143:7)
  at IncomingMessage.emit (events.js:129:20)
  at _stream_readable.js:908:16
  </code></pre>
  
  <p>Now I am assuming this is the same cause as this question <a href="https://stackoverflow.com/questions/16781294/passport-js-passport-initialize-middleware-not-in-use">passport.js passport.initialize() middleware not in use</a> but cannot see what order the calls should be in my code.</p>
  
  <p>So can anyone tell me what order to place the various parts of the code.</p>
  
  <p>Thanks</p>