Get status parameters from OAuth callback in passport

I am trying to send state parameters to Oauth and then catch them in a callback, but I cannot get it to work. So passport functions support such functionality?

My idea is to send id as a status parameter to Oauth, and then in a callback depending on the identifier from the state parameters sent back to my application. I want to do the right redirect.

In Twitter strategy, I have included

passReqToCallback: true,
state: true

My request should look like this:

app.get('/auth/twitter/:gameId/:url',
    function(req, res){
        try {
            var json = JSON.stringify({gameId: req.params.gameId, url: req.params.url});
            var encodedValues = base64url(json);
            console.log('encodedValues:'+encodedValues)
            passport.authenticate('twitter', {state:encodedValues})
        }catch (e){
            console.log(e);
        }
    }
);  

then on the callback

app.get('/auth/twitter/callback', passport.authenticate('twitter', function(req, res, next) {
try{
    //get the state params from the res uri/body
    //decode the state params
    //redirect depending on the state.gameId
}catch(e){
    console.log('twitter exception:'+e);
}}));

I already know that I can save the identifier in the session, but I would like to know if there is less session to do this by passing this information from the URL as it is not sensitive.

thank

+4

All Articles