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

前端 未结 2 938
我寻月下人不归
我寻月下人不归 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
    

提交回复
热议问题