derby-user-providers

Add third party provider support to derby-user

Derby User Providers

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

$ npm install derby-user-providers --save

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')
  }
};

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

Visit /user/auth/facebook.

/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.