I am just starting to learn Node, and Express (MEAN stack) and I am wondering, can PassportJS be used to make queries to the Twitter API v1.1, or is it used solely for authentication?
I've built the following code, but I am not getting anything desirable back from it (application crashes):
My Controller:
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
async = require('async'),
passport = require('passport'),
TwitterStrategy = require('passport-twitter').Strategy,
_ = require('underscore');
exports.auth = function(req, res, passport) {
passport.use(new TwitterStrategy({
consumerKey: '7rTisA540o3BkQPRItqog',
consumerSecret: 'u5f4xShik2GSypDu7pFuXpRlf23nZdS1CeZCMSXE',
callbackURL: "http://localhost:3000/auth/twitter/callback"
},
function(token, tokenSecret, profile, done) {
console.log(token, tokenSecret, profile, done);
}
));
};
Routes:
// Twitter API
app.get('/twitter', twitter.auth);
When I hit Localhost:3000/twitter, I end up with the following message:
TypeError: Object function callbacks(err) {
var fn = route.callbacks[i++];
try {
if ('route' == err) {
nextRoute();
} else if (err && fn) {
if (fn.length < 4) return callbacks(err);
fn(err, req, res, callbacks);
} else if (fn) {
if (fn.length < 4) return fn(req, res, callbacks);
callbacks();
} else {
nextRoute(err);
}
} catch (err) {
callbacks(err);
}
} has no method 'use'
at exports.auth (/Users/nfento/Sites/mean-stack/app/controllers/twitter.js:12:16)
at callbacks (/Users/nfento/Sites/mean-stack/node_modules/express/lib/router/index.js:164:37)
at param (/Users/nfento/Sites/mean-stack/node_modules/express/lib/router/index.js:138:11)
at pass (/Users/nfento/Sites/mean-stack/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/Users/nfento/Sites/mean-stack/node_modules/express/lib/router/index.js:173:5)
at Object.router (/Users/nfento/Sites/mean-stack/node_modules/express/lib/router/index.js:33:10)
at Context.next (/Users/nfento/Sites/mean-stack/node_modules/express/node_modules/connect/lib/proto.js:190:15)
at Context.actions.pass (/Users/nfento/Sites/mean-stack/node_modules/passport/lib/passport/context/http/actions.js:77:8)
at SessionStrategy.authenticate (/Users/nfento/Sites/mean-stack/node_modules/passport/lib/passport/strategies/session.js:67:10)
at attempt (/Users/nfento/Sites/mean-stack/node_modules/passport/lib/passport/middleware/authenticate.js:243:16)
I'm completely new to this, I was hoping to get the auth token and then from there I can go an query the API, however, I can't get past the first step. Am I doing something wrong in my code, or am I using the Passport library incorrectly?