Skip to content
Add third party provider support to derby-user
Latest commit 354eb41 Sep 21, 2014 @psirenny fix readme typo
Failed to load latest commit information.
lib major refactor and readme update Sep 21, 2014
.gitignore first commit Jul 28, 2013
LICENSE add license, edit package.json Nov 18, 2013 fix readme typo Sep 21, 2014
index.js update to match newer version of derby-user Sep 21, 2014
package.json 0.7.0 Sep 21, 2014

Derby User Providers

Add 3rd party providers to derby-user such as facebook, google, twitter, etc…


$ npm install derby-user-providers --save

Server Usage

In your server file, add the middleware:

var providers = require('derby-user-providers');

var google = {
  config: {
    clientID: '...',
    clientSecret: '...',
    strategy: {
      module: 'passport-google-oauth',
      name: 'OAuth2Strategy'

var facebook = {
  config: {
    clientID: '...',
    clientSecret: '...',
    authOptions: {scope: ['email']},
    strategy: require('passport-facebook').Strategy

  // ...
  // ...
  // cookieParser, session, transport, model, bodyParser...
  // ...
  // ...
  .use('/user', providers({
    origin: 'http://localhost',
    path: '/user',
    providers: {facebook: facebook, google: google}

App Usage

In your view:

<a href="/user/auth/facebook">Sign in with Facebook</a>
<a href="/user/auth/google">Sign in with Google+</a>

Handling events

You can handle events.

var events = require('events');
var emitter = new events.EventEmitter();

emitter.on('user.auth', function (req, data) {
  var model = req.getModel();
  console.log('user ' + data.userId + ' signed in.');

  // ...
  // ...
    emitter: emitter, ...


/auth/:provider?params – Call this route to authenticate a user. The params are merged into authOptions.

/auth/:provider/done – This route is called when authentication is done. Can be overriden. Redirects to / by default.


originRequired. The site origin providers will redirect back to upon sign in.

emitter – Specify an event emitter that will handle events.

path – Must be set if you use an express path prefix. (See above)

providers – An object containing providers and their configuration settings.


config – Configuration options for the strategy. Refer to the passport strategy's docs.

strategy – The passport strategy function or an object with the strategy name and/or module.

authOptions – Passport authenticate options passed in during verification. Used to pass in scope, etc.

callbackOptions – Passport authenticate options passed in during the callback.


user.auth(req, data) – Event emitted when a new user authenticates. Contains userId and provider name.

Something went wrong with that request. Please try again.