imns
imns

Reputation: 5082

passportjs get users twitter credentials

I want to authenticate a user via passport's twitter strategy, but not sign the user in. All I want to do is store their credentials so I can tweet to their account at a later date, but I'm not seeing how this is possible.

It looks like you have to call the done callback which then stores the users id in the session. My user is already authenticated with my application, but wants to attach one or more twitter account that they can choose to tweet to at a later date.

Here's my Twitter strategy

passport.use(new TwitterStrategy({

        consumerKey: '...',
        consumerSecret: '...',
        callbackURL: '/add/twitter/callback',
        passReqToCallback: true

    },
    function(req, token, tokenSecret, profile, done) {
        process.nextTick(function() {
          //save the users twitter credentials for use later on and call 
          //my custom callback here ...
        });

    });

 }));

I'm also using express.js so here is are my routes

router
   .get('/auth/twitter', passport.authenticate('twitter'))
   .get('/auth/twitter/callback',
        passport.authenticate('twitter'), function(req, res) {
            console.log('made it here');
            // Successful authentication
            res.render('manager/add-twitter', {});
        });

Is it possible to have a custom callback that gets fired no matter what?

Upvotes: 0

Views: 182

Answers (1)

imns
imns

Reputation: 5082

As it turns out, you can do this using authorize instead of authenticate. Here's the docs for anyone who's interested: http://passportjs.org/guide/authorize/

Upvotes: 1

Related Questions