Cannot GET /auth/twitter/callback while using twitter oauth in nodejs

前端 未结 2 939
我寻月下人不归
我寻月下人不归 2021-01-07 03:31

I\'m trying to do twitter oauth in nodejs using passportjs but getting error

Cannot GET /auth/twitter/callback?oauth_token=alksdkalsjdsjd23232378skjdfjsdhf&a         


        
相关标签:
2条回答
  • 2021-01-07 03:59

    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
    
    0 讨论(0)
  • 2021-01-07 04:06

    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

    0 讨论(0)
提交回复
热议问题