Skip to content Skip to sidebar Skip to footer

Cannot Get /auth/twitter/callback While Using Twitter Oauth In Nodejs

I'm trying to do twitter oauth in nodejs using passportjs but getting error Cannot GET /auth/twitter/callback?oauth_token=alksdkalsjdsjd23232378skjdfjsdhf&oauth_verifier=23

Solution 1:

EDIT There is missing / in auth/twitter/callback route definition.

Also for the routers /auth/twitter and auth/twitter/callback, passport.authenticate() as middleware will do the authentication, and you should have route handling functions.

So the definition of your routes should look something like:

app.get('/auth/twitter', 
         passport.authenticate('twitter'),
         function(req, res) {}); // empty route handler function, it won't be triggered
app.get('/auth/twitter/callback', 
         passport.authenticate('twitter', { 
                                successRedirect: '/success',
                                failureRedirect: '/login' }),
         function(req, res) {}); // route handler

Solution 2:

You don't need the empty route handler function(req, res) {} - you can just leave the argument out and express will understand you don't plan on ever using the handler

Post a Comment for "Cannot Get /auth/twitter/callback While Using Twitter Oauth In Nodejs"