Search code examples
javascriptnode.jspassport.jskoapassport-twitter

Issue with passport-twitter strategy


I have an app I've written in node with Koa. I'm using passport for authentication, passport-twitter for twitter oauth, and koa-passport to make it work with Koa. Up until recently, everything with the login was working perfectly. I started to attract some interest on github from friends, and when I tried to get new people spun up on the project, people started to have issues not being able to login and getting this message:

Whoa there! There is no request token for this page. That's the special key we need from applications asking to use your Twitter account. Please go back to the site or application that sent you here and try again; it was probably just a mistake.

The weird thing is, my production server is up to date with the repository, and the login there works just fine. The login on both of my local machines works as well. When I deleted the project entirely from my laptop and brought it down again though, it started having the issue too.

Here's the code in my auth.js

var passport = require('koa-passport');
var settings = require('./settings');
var Promise = require('../plugins/base/common').Promise;
var config = require('../config.json');

passport.serializeUser(function(user, done) {
  done(null, user)
})

passport.deserializeUser(function(user, done) {
  done(null, user)
})

if (process.env.NODE_ENV == "production"){
  var domainStr = "http://productionurl.com";
}else{
  var domainStr = "http://127.0.0.1:3000";
}

var TwitterStrategy = require('passport-twitter').Strategy
passport.use(new TwitterStrategy({
  consumerKey: config.app.data.passport_twitter.consumerKey,
  consumerSecret: config.app.data.passport_twitter.consumerSecret,
  callbackURL: domainStr + '/auth/twitter/callback'
},
Promise.coroutine(function * (token, tokenSecret, profile, done) {
  user = yield settings.createUser(profile, "twitter");
  done(null, user);
})

))

I've done a diff of npm list on production and locally to try to make them match, and even with them matching, my laptop gets that error.

I've checked my clock, and that's right, so I'm completely out of ideas.

Full code is here: http://github.com/snollygolly/bloodhound

Thank you in advance. :)


Solution

  • We finally figured out the issue.

    Koa's website says to do n 0.11 which was loading n 0.11.15.

    Unfortunately, something in passport or koa-passport doesn't work with that version. Reverting to n 0.11.14 resolves the issue.