title: NODE/EXPRESS/PASSPORT - Facebook App with Callback URL
body: <p>I am creating a facebook app. And I want to let users to login to my website using FB. I have integrated the code but FB cannot found the callback page/url.</p>
  
  <p>URL: <a href="http://www.mywebsite.com:3000/auth/facebook/callback?code=" rel="nofollow">http://www.mywebsite.com:3000/auth/facebook/callback?code=</a>{here_goes_the_callback_code}
  Error: The webpage cannot be found</p>
  
  <p>app.js</p>
  
  <pre><code>var express = require('express');
  var routes = require('./routes');
  var http = require('http');
  var path = require('path');
  
  var passport = require('passport');
  passport.serializeUser(function(user, done) {
  done(null, user);
  });
  
  passport.deserializeUser(function(obj, done) {
    done(null, obj);
  });
  
  // begin facebook passport --&gt;
  var FacebookStrategy = require('passport-facebook').Strategy;
  var FACEBOOK_APP_ID = "---MY_FB_APP_ID---"
  var FACEBOOK_APP_SECRET = "---MY_FB_APP_SECRET---";
  
  passport.use(new FacebookStrategy({
      clientID: FACEBOOK_APP_ID,
      clientSecret: FACEBOOK_APP_SECRET,
      callbackURL: "http://www.mywebsite.com:3000/auth/facebook/callback"
   },
   function(accessToken, refreshToken, profile, done) {
      process.nextTick(function () {    
        return done(null, profile);
      });
    }
  ));
  // &lt;-- end facebook passport
  
  var app = express();
  var v_login = require('./routes/login');
  
  app.use(passport.initialize());
  app.use(passport.session());
  
  app.get('/login', v_login.login);
  
  app.get('/auth/facebook',
    passport.authenticate('facebook'),
    function(req, res){
    //this function will not be called
    });
  
  app.get('/auth/facebook/callback', 
      passport.authenticate('facebook', { 
          successRedirect : '/home',
          failureRedirect: '/login'
      })
  );
  
  var isAuthenticated = function (req, res, next) {
      app.get('/home', isAuthenticated, function(req, res, next) {
      console.log("fb.user:"+req.user);
      res.render('home');
      });
  }
  
  
  http.createServer(app).listen(app.get('port'), function(){
    console.log('Express server listening on port ' + app.get('port'));
  });
  
  function ensureAuthenticated(req, res, next) {
    if (req.isAuthenticated()) { return next(); }
    res.redirect('/login')
  }
  </code></pre>
  
  <p>facebook.jade</p>
  
  <pre><code>doctype html
  html(lang='en')
  body
  a(href='/auth/facebook') Facebook App
  </code></pre>
  
  <p>Thanks in advance!</p>