1.2.2 • Published 4 years ago

transports v1.2.2

Weekly downloads
53
License
MIT
Repository
github
Last release
4 years ago

Transports

Passport-enabled conventional authentication provider handling simplification

Install

npm i -S transports

.configure(data)

See Configuring data below for an example data object. This is used across transports to access the different authentication providers you want to set up, your passport instance, and other configuration options.

.passports(handler)

Configures passport with the authentication providers passed to data.providers. It will invoke passport.use passing your strategy and then telling it to call handler for each of those providers, normalizing authentication across providers.

handler(query, profile, done)

The handler method should be used to lookup the user, and maybe create a new one if the user isn't found.

  • The query will be something like { googleId: '...' }, { facebookId: '...' }, etc.
  • The profile argument is the data returned by the authentication provider
  • The done callback is the one described in the passport documentation

.routing(app, handler)

Sets up routing for the selected providers. The handler is only used when the user needs a new account.

.serialization(field?)

Sets up serialization and deserialization. The _id field is used by default, but you can provide another one.

transports.serialization('id');

Configuring data

Here's a real-world data object example. Note that you need to pass in your own passport instance, because that way you'll stay in control.

{
  passport: require('passport'),
  authority: process.env.AUTHORITY,
  success: '/',
  login: '/authentication/login',
  logout: '/authentication/logout',
  local: '/authentication/login/local',
  providers: {
    facebook: {
      get enabled () { return this.id && this.secret; },
      strategy: require('passport-facebook').Strategy,
      protocol: 'oauth2',
      id: process.env.FACEBOOK_APP_ID,
      secret: process.env.FACEBOOK_APP_SECRET,
      link: '/authentication/login/facebook',
      callback: '/authentication/login/facebook/callback',
      options: { scope: 'email' }
    },
    google: {
      get enabled () { return this.id && this.secret; },
      strategy: require('passport-google-oauth').OAuth2Strategy,
      protocol: 'oauth2',
      id: process.env.GOOGLE_CLIENT_ID,
      secret: process.env.GOOGLE_CLIENT_SECRET,
      link: '/authentication/login/google',
      callback: '/authentication/login/google/callback',
      options: { scope: 'openid email' }
    },
    linkedin: {
      get enabled () { return this.id && this.secret; },
      strategy: require('passport-linkedin').Strategy,
      protocol: 'oauth1',
      id: process.env.LINKEDIN_API_KEY,
      secret: process.env.LINKEDIN_API_SECRET,
      link: '/authentication/login/linkedin',
      callback: '/authentication/login/linkedin/callback',
      options: { scope: ['r_basicprofile', 'r_emailaddress'] },
      fields: ['id', 'first-name', 'last-name', 'email-address']
    }
  }
}

License

MIT

1.2.2

4 years ago

1.2.0

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

6 years ago

0.2.4

6 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago