npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

transports

v1.2.2

Published

Passport-enabled conventional authentication provider handling simplification

Downloads

19

Readme

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