Passpack
Multi-tenancy (read: virtual hosts) for Passport.JS
Overview
Passpack makes things easier if you're running a multi-tenanted application with Passport.JS by abstracting away some of the book keeping involved with instantiating multiple passport instances and choosing which to use for a given request.
Installation
Available via npm:
$ npm install passpack
Or via git:
$ npm install git://github.com/deoxxa/passpack.git
Usage
Passpack provides a framework for applications to define their own passport.js
multi-tenanting implementations. It requires you to provide two functions:
_getConfig
and _createInstance
. These functions are called when necessary to
do exactly what they sound like they do, allowing you to completely control the
configuration and instantiation of the passport objects managed by passpack.
You can see an example of how this all fits together below, in the "example" section.
_getConfig
The _getConfig
function is used to work out what the configuration parameters
are for passport for a given request. It's provided with the request object from
express, and is expected to call the callback function when it's done with an
error (or null), an ID, and optionally some configuration parameters for
_createInstance
to use in instantiating the passport object.
passpack { ;};
_createInstance
The createInstance
function is used to actually instantiate a passport object.
It's only called when a cached object isn't already available, providing a means
of lazy instantiation. It's given some configuration parameters (from
_getConfig
) and is expected to call the callback function with an error (or
null) and the resultant passport instance.
passpack { var instance = ; instance; instance; instance; ;};
API
constructor
Constructs a new Passpack object, optionally providing the _getConfig
and
_createInstance
functions in an object.
options;
// basic instantiationvar passpack = ; // instantiation with functionsvar passpack = getConfig: myGetConfig createInstance: myCreateInstance;
Arguments
- options - an object specifying values for
_getConfig
and_createInstance
attach
Returns an express/connect-compatible middleware function that attaches the correct passport object to a request. You probably want this as the first passpack-related piece of middleware in your application.
passpack;
app;
middleware
Wraps a passport middleware function so that it'll be called using the correct passport instance, optionally passing some arguments to it.
passpack;
app;
Arguments
- name - name of the passport middleware function.
- argN - arguments to be passed to the middleware.
#added
added
is an event that's fired with the id of a passport object after it's
created and added to the passpack collection.
passpack;
passpack;
Parameters
- id - id of the passport instance.
- instance - the passport instance itself.
Example
Also see example.js.
// $ npm install express passpack passport passport-http var express = Passpack = Passport = Passport BasicStrategy = BasicStrategy; var passpack = ; passpack { return ;}; passpack { var instance = ; instance; instance; instance; ;}; var app = ; app;app;app;app;app;app;app; app; app; app;
License
3-clause BSD. A copy is included with the source.
Contact
- GitHub (deoxxa)
- Twitter (@deoxxa)
- ADN (@deoxxa)
- Email (deoxxa@fknsrs.biz)