title: InternalOAuthError: Failed to obtain access token
body: <p>Can anyone help me with what is wrong with the below code in the link <a href="https://gist.github.com/adrai/6728056" rel="noreferrer">GitHub</a>
  oauth2-provider server with passport-oauth2 consumer</p>
  
  <p>After I login with <code>http://localhost:8082</code> and reach my callback URL:
  <code>http://localhost:8081/auth/provider/callback</code>, it throws an error </p>
  
  <pre><code>var express = require('express')
    , passport = require('passport')
    , util = require('util')
    , TwitterStrategy = require('passport-twitter').Strategy;
  
  var TWITTER_CONSUMER_KEY = "--insert-twitter-consumer-key-here--";
  var TWITTER_CONSUMER_SECRET = "--insert-twitter-consumer-secret-here--";
  
  passport.serializeUser(function(user, done) {
    done(null, user);
  });
  
  passport.deserializeUser(function(obj, done) {
    done(null, obj);
  });
  
  passport.use(new TwitterStrategy({
      consumerKey: TWITTER_CONSUMER_KEY,
      consumerSecret: TWITTER_CONSUMER_SECRET,
      callbackURL: "http://127.0.0.1:3000/auth/twitter/callback"
    },
    function(token, tokenSecret, profile, done) {
      // asynchronous verification, for effect...
      process.nextTick(function () {
  
        return done(null, profile);
      });
    }
  ));
  
  
  var app = express.createServer();
  
  // configure Express
  app.configure(function() {
    app.set('views', __dirname + '/views');
    app.set('view engine', 'ejs');
    app.use(express.logger());
    app.use(express.cookieParser());
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(express.session({ secret: 'keyboard cat' }));
    app.use(passport.initialize());
    app.use(passport.session());
    app.use(app.router);
    app.use(express.static(__dirname + '/public'));
  });
  
  
  app.get('/', function(req, res){
    res.render('index', { user: req.user });
  });
  
  app.get('/account', ensureAuthenticated, function(req, res){
    res.render('account', { user: req.user });
  });
  
  app.get('/login', function(req, res){
    res.render('login', { user: req.user });
  });
  
  app.get('/auth/twitter',
    passport.authenticate('twitter'),
    function(req, res){
      // The request will be redirected to Twitter for authentication, so this
      // function will not be called.
    });
  
  app.get('/auth/twitter/callback', 
    passport.authenticate('twitter', { failureRedirect: '/login' }),
    function(req, res) {
      res.redirect('/');
    });
  
  app.get('/logout', function(req, res){
    req.logout();
    res.redirect('/');
  });
  
  app.listen(3000);
  
  function ensureAuthenticated(req, res, next) {
    if (req.isAuthenticated()) { return next(); }
    res.redirect('/login')
  } 
  </code></pre>
  
  <blockquote>
    <p><strong>InternalOAuthError: Failed to obtain access token</strong></p>
  </blockquote>
  
  <p>How can I resolve this issue?</p>