Pass additional variables to Passport-Twitter

2

I need to pass an additional variable to the login with Twitter of passport , it would be something like this:

app.get('/twitter',
    function (req, res) {
        var variableallegar = req.query.idunico;
    }, passport.authentication('twitter');
    app.get('/twitter/callback', function (req.res) {
        //ACA ME LLEGA EL PERFIL DEL USUARIO
        //quisiera que tambien me llege,
        //variableallegar
});

How could I do it?

    
asked by Gatoo 12.10.2016 в 17:21
source

1 answer

0

Beware that you have a typo in app.get('/twitter/callback', function (req.res) { , the req.res should be req, res .

You can pass parameters between middlewares (each function that you assign to the router) through the req. Although I do not understand very well how you have assigned the middlewares there, try this way:

app.get('/twitter/callback',
    function (req, res) {
        req.variableallegar = req.query.idunico;
    }, 
    passport.authentication('twitter'), 
    function (req, res) {
        var variableallegar = req.variableallegar;
        //Aunque desde aqui tambien deberias poder acceder a req.query.idunico
    }
);
    
answered by 26.01.2017 в 18:05