# transports

> Passport-enabled conventional authentication provider handling simplification

Latest version **1.2.2** (published 2016-10-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install transports
pnpm add transports
yarn add transports
bun add transports
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2016-10-05 |
| First published | 2014-06-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | bevacqua |

## Links

- npm: https://www.npmjs.com/package/transports
- Repository: https://github.com/bevacqua/transports
- Issues: https://github.com/bevacqua/transports/issues
- npm.io page: https://npm.io/package/transports

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^2.4.1
- [assignment](https://npm.io/package/assignment.md) 2.2.0

## Recent versions

- 1.2.2 (latest) — 2016-10-05
- 1.2.0 — 2016-10-05
- 1.1.4 — 2016-10-05
- 1.1.3 — 2016-10-04
- 1.1.1 — 2016-10-04
- 1.1.0 — 2016-08-19
- 1.0.0 — 2014-09-19
- 0.2.4 — 2014-09-03
- 0.2.3 — 2014-06-20
- 0.2.2 — 2014-06-18
- 0.2.1 — 2014-06-17
- 0.2.0 — 2014-06-17
- 0.1.1 — 2014-06-16
- 0.1.0 — 2014-06-16

## README

# Transports

> Passport-enabled conventional authentication provider handling simplification

# Install

```shell
npm i -S transports
```

# `.configure(data)`

See [Configuring `data`](#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][1]

# `.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.

```js
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.

```js
{
  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]: http://passportjs.org/guide/configure/

---
_Source: https://npm.io/package/transports · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
