Using Everyauth / Express and multiple configurations?

I successfully use Node.js + Express + Everyauth ( https://github.com/abelmartin/Express-And-Everyauth/blob/master/app.js ) to log in to Facebook, Twitter, etc. from my application.

The problem I'm trying to circle my head with is that Everyauth seems to "set up and forget." I created one everyauth object and configured it as an expression middleware, and then forgot about it. For example, if I want to create a mobile login on Facebook, I do:

var app = express.createServer(); everyauth.facebook .appId('AAAA') .appSecret('BBBB') .entryPath('/login/facebook') .callbackPath('/callback/facebook') .mobile(true); // mobile! app.use(everyauth.middleware()); everyauth.helpExpress(app); app.listen(8000); 

Here's the problem: Both mobile and non-mobile clients will connect to my server, and I do not know what it is connecting to until a connection is established. Worse, I need to support multiple Facebook application identifiers (and, again, I don't know which one I want to use until the client connects and I partially analyze the input). Since everyauth is a singleton that was configured once, I don’t see how to make these configuration changes based on the request made.

It seems that I need to create some middleware that acts before everyauth middleware to configure everyauth object, so that everyauth subsequently uses the correct appId / appSecret / mobile parameters. I have no idea how to do this ...

Suggestions?

Here is the best idea that I have so far, although it seems awful: Create an everyauth object for each possible configuration, using a different entryPath for each ...

+4
source share
1 answer

Apparently, I jumped from a gun and wrote this before a morning cup of coffee, because I answered my question, and it was pretty easy to implement. Basically, I just needed to create my own custom middleware to switch everyauth configuration before everyauth gets its dirty paws on demand, so ...

 var configureEveryauth = function() { return function configure(req, res, next) { // make some changes to the everyauth object as needed.... next(); }; } 

and now my setup will be as follows:

 var app = express.createServer(); everyauth.facebook .entryPath('/login/facebook') .callbackPath('/callback/facebook'); app.use(configureEveryauth()); app.use(everyauth.middleware()); everyauth.helpExpress(app); app.listen(8000); 

Please note that I don’t even worry about fully setting up everyauth Facebook object at startup, as I know that the middleware will fill in the missing parameters.

0
source

All Articles