old_contents: var loopback = require('loopback');
  var boot = require('loopback-boot');
  var app = module.exports = loopback();
  
  // Passport configurators..
  var loopbackPassport = require('loopback-component-passport');
  var PassportConfigurator = loopbackPassport.PassportConfigurator;
  var passportConfigurator = new PassportConfigurator(app);
  
  // attempt to build the providers/passport config
  var config = {};
  try {
  	config = require('../providers.json');
  } catch (err) {
  	console.trace(err);
  	process.exit(1); // fatal
  }
  
  // Set up the /favicon.ico
  app.use(loopback.favicon());
  
  // request pre-processing middleware
  app.use(loopback.compress());
  
  // -- Add your pre-processing middleware here --
  app.use(loopback.token({
  	model: app.models.accessToken
  }));
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  
  // boot scripts mount components like REST API
  boot(app, __dirname);
  
  app.use(loopback.cookieParser(app.get('cookieSecret')));
  app.use(loopback.session({
  	secret: 'kitty',
  	saveUninitialized: true,
  	resave: true
  }));
  passportConfigurator.init();
  
  passportConfigurator.setupModels({
  	userModel: app.models.user,
  	userIdentityModel: app.models.userIdentity,
  	userCredentialModel: app.models.userCredential
  });
  for (var s in config) {
  	var c = config[s];
  	c.session = c.session !== false;
  	passportConfigurator.configureProvider(s, c);
  }
  var ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn;
  
  app.get('/', function(req, res, next) {
    res.render('index', {user: req.user});
  });
  
  app.get('/auth/account', ensureLoggedIn('/login.html'), function(req, res, next) {
    res.render('loginProfiles', {user: req.user});
  });
  
  app.get('/link/account', ensureLoggedIn('/login.html'), function(req, res, next) {
    res.render('linkedAccounts', {user: req.user});
  });
  
  app.get('/auth/logout', function(req, res, next) {
    req.logout();
    res.redirect('/');
  });
  
  // -- Mount static files here--
  // All static middleware should be registered at the end, as all requests
  // passing the static middleware are hitting the file system
  // Example:
  var path = require('path');
  app.use(loopback.static(path.resolve(__dirname, '../client/public')));
  
  // Requests that get this far won't be handled
  // by any middleware. Convert them into a 404 error
  // that will be handled later down the chain.
  app.use(loopback.urlNotFound());
  
  // The ultimate error handler.
  app.use(loopback.errorHandler());
  
  app.start = function() {
  	// start the web server
  	return app.listen(function() {
  		app.emit('started');
  		console.log('Web server listening at: %s', app.get('url'));
  	});
  };
  
  // start the server if `$ node server.js`
  if (require.main === module) {
  	app.start();
  }
  
new_contents: var loopback = require('loopback');
  var boot = require('loopback-boot');
  var app = module.exports = loopback();
  
  // Passport configurators..
  var loopbackPassport = require('loopback-component-passport');
  var PassportConfigurator = loopbackPassport.PassportConfigurator;
  var passportConfigurator = new PassportConfigurator(app);
  
  // attempt to build the providers/passport config
  var config = {};
  try {
  	config = require('../providers.json');
  } catch (err) {
  	console.trace(err);
  	process.exit(1); // fatal
  }
  
  // Set up the /favicon.ico
  app.use(loopback.favicon());
  
  // request pre-processing middleware
  app.use(loopback.compress());
  
  // -- Add your pre-processing middleware here --
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  
  // boot scripts mount components like REST API
  boot(app, __dirname);
  
  // The access token is only available after boot
  app.use(loopback.token({
    model: app.models.accessToken
  }));
  
  app.use(loopback.cookieParser(app.get('cookieSecret')));
  app.use(loopback.session({
  	secret: 'kitty',
  	saveUninitialized: true,
  	resave: true
  }));
  passportConfigurator.init();
  
  passportConfigurator.setupModels({
  	userModel: app.models.user,
  	userIdentityModel: app.models.userIdentity,
  	userCredentialModel: app.models.userCredential
  });
  for (var s in config) {
  	var c = config[s];
  	c.session = c.session !== false;
  	passportConfigurator.configureProvider(s, c);
  }
  var ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn;
  
  app.get('/', function(req, res, next) {
    res.render('index', {user: req.user});
  });
  
  app.get('/auth/account', ensureLoggedIn('/login.html'), function(req, res, next) {
    res.render('loginProfiles', {user: req.user});
  });
  
  app.get('/link/account', ensureLoggedIn('/login.html'), function(req, res, next) {
    res.render('linkedAccounts', {user: req.user});
  });
  
  app.get('/auth/logout', function(req, res, next) {
    req.logout();
    res.redirect('/');
  });
  
  // -- Mount static files here--
  // All static middleware should be registered at the end, as all requests
  // passing the static middleware are hitting the file system
  // Example:
  var path = require('path');
  app.use(loopback.static(path.resolve(__dirname, '../client/public')));
  
  // Requests that get this far won't be handled
  // by any middleware. Convert them into a 404 error
  // that will be handled later down the chain.
  app.use(loopback.urlNotFound());
  
  // The ultimate error handler.
  app.use(loopback.errorHandler());
  
  app.start = function() {
  	// start the web server
  	return app.listen(function() {
  		app.emit('started');
  		console.log('Web server listening at: %s', app.get('url'));
  	});
  };
  
  // start the server if `$ node server.js`
  if (require.main === module) {
  	app.start();
  }
  
subject: Fix the token middleware