Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sails.js with passport-twitter

I am integrating passport with sails.

While google and facebook is working fine in my application I struggle with twitter authentication! When clicking on the 'login with twitter' button there is an error thrown wich says: Error: OAuthStrategy requires session support. Did you forget app.use(express.session(...))?

I read here that sessions are necessary for twitter authentication to work. I made sure my app has sessions activated!

I testet passport-twitter with a simple express app (without sails) to make sure the module is working and my twitter credentials are intact.

I am assuming sails sessions are different to express sessions? Is sails changing the way sessions work? Any advice on how to solve this?


EDIT: Added some more info as requested in the comments:

Sails Version: 0.9.13

UserController.js:

...
twitter: function(res, req) {
    passport.authenticate('twitter', {failureRedirect: '/login'}, function(err, user, info) {
      return console.log(err, user, info);
    })(req, res);
  }
...

config/passport.js:

...
passport.use(new TwitterStrategy({
    consumerKey: '**************',
    consumerSecret: '********************',
    callbackURL: "http://127.0.0.1:1337/auth/twitter/callback"
  },
  function(token, tokenSecret, profile, done){
    process.nextTick(function() {
      console.log(profile);
    });
  }
));
...
like image 610
Sven Avatar asked Mar 24 '14 11:03

Sven


Video Answer


1 Answers

Did you try sails-generate-auth with sails 0.10? It makes life easier from my point of view: https://www.npmjs.org/package/sails-generate-auth

like image 105
Diego Pamio Avatar answered Oct 30 '22 00:10

Diego Pamio