You can't change Twitter (or any other OAuth provider), they all offer only one callback to one domain. An easy solution is to re-route all requests from http://domain.com to http://www.domain.com, so all visitors end up at www.domain.com before authenticating. You should be able to do this on your DNS or with a req.header redirect server-side:
app.get('/*', function(req, res, next) {
if (req.headers.host.match(/^www/) !== null ) {
res.redirect('http://' + req.headers.host.replace(/^www\./, '') + req.url);
} else {
next();
}
})
Copied from this answer.
When authenticating with passport.js, try to specify the callback url:
passport.use(new TwitterStrategy({
consumerKey: auth_keys.twitter.consumerKey,
consumerSecret: auth_keys.twitter.consumerSecret,
callbackURL: auth_keys.twitter.callbackURL
},
function(token, tokenSecret, profile, done) {
process.nextTick(function () {
User.twitterAuth({ profile: profile }, function (err, user) {
return done(err, user);
});
});
}
));
And make sure the callbackURL is exactly the same as configured in Twitter. If you're running node for development on localhost, try two different key files and create another authentication apps on twitter with 127.0.0.1:3000 as callback address. You can switch key files for dev and production:
if (app.get('env') == 'development') {
auth_keys = require('./lib/keys_dev');
}
if (app.get('env') == 'production') {
auth_keys = require('./lib/keys_live');
}