Sven
Sven

Reputation: 6338

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);
    });
  }
));
...

Upvotes: 6

Views: 1650

Answers (3)

Travis Webb
Travis Webb

Reputation: 15018

I recommend that you don't spend time integrating this yourself. There are a number of existing solutions. The official documentation lists several options:

  • sails-auth: Passport-based Authentication Extension, including Basic Auth
  • sails-permissions: Permissions and Entitlements system for sails.js: supports user authentication with passport.js, role-based permissioning, object ownership, and row-level security.
  • sails-generate-auth: Generate a Passport.js authentication layer for your Sails app

Upvotes: 0

ronky
ronky

Reputation: 1

check out one example how to do Twitter auth (google, facebook, github are there as well): https://github.com/stefanbuck/sails-social-auth-example

Upvotes: 0

Diego Pamio
Diego Pamio

Reputation: 1358

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

Upvotes: 2

Related Questions