meteor/meteor — pull request #1913 by timhaines (2014-03-12 18:35:05+00:00)
Title: Move oauth login results from ram to mongo, giving all servers access

The oauth implementation before this commit stored oauth results in ram. This strategy works well if the app is running on a single server, or is using session cookies for consistent routing across multiple servers. It doesn't work if the app is running on multiple servers and the proxy server is using the path for routing.

The problem is that there's no way to guarantee that the server handling the oauth credential redirect url is the same server that the user's sockjs connection is with (user's server). It's the user's server that knows what to do with the oauth credentials, so it needs access to stored credentials.

This pull request updates the oauth process to temporarily store the credentials in mongo rather than in ram, giving the user's server access.

A few of points of note:
* Once Emily's work of adding encryption to oauth storage is done, it should also be added to `Oauth._storeTransientResult` and `Oauth._retrieveTransientResult` so credentials aren't stored in plain text.
* Occasionally a background process should run which clears any orphaned _transientResult records from mongo. This has not been implemented, but is now more important seeing as the credentials are in mongo rather than RAM.
* This implementation three extra mongo requests (Insert, Find, Remove) to the oauth flow. It's possible using mongo could be made optional so apps that don't need this aren't slowed down. Consulting with Emily, she advised keeping the implementation simple and not adding this option.