jaredhanson/passport-oauth2 — pull request #4 by kbeyer (2013-10-14 21:11:39+00:00)
Title: Add option to pass URL query params through oAuth flow via state parameter

It is tricky to pass application specific state/variables through with current implementation. This change is how I have been able to work around the issue.

Example use with facebook auth:

Route setup...
```javascript
app.get('/auth/facebook', passport.authenticate('facebook', {
scope: ['email', 'user_about_me'],
failureRedirect: '/signin'
}), users.signin);

app.get('/auth/facebook/callback', passport.authenticate('facebook', {
failureRedirect: '/signin'
}), users.authCallback);
```

Passport strategy setup...
```javascript
passport.use(new FacebookStrategy({
clientID: config.facebook.clientID,
clientSecret: config.facebook.clientSecret,
callbackURL: config.facebook.callbackURL,
passReqToCallback: true,
passSourceQueryViaState: true
},
function(req, accessToken, refreshToken, profile, done) {

var passThroughParams = JSON.parse( decodeURIComponent( req.query.state) );
...
```

Also available via auth callback...
```javascript
exports.authCallback = function(req, res, next) {
var passThroughParams = JSON.parse( decodeURIComponent( req.query.state) );
res.redirect('/');
};
```

NOTE: This implementation is as simple as possible not to introduce potential conflicts in other scenarios that use state. Another option I considered was to automatically include the query params as a subset of the state (e.g - state = {appstate: ksafljsafd, queryparams: {foo: 'bar'}}). This would enable the module to handle all serialization and then merge the state.queryparams back into the req.query before it is passed back making the flow seem more natural. Obviously such an implementation would require a more complex implementation.

Would love to hear thoughts on another way to enable this feature as well.