passport-open-humans

5.2.0 • Public • Published

Passport-Open Humans

Passport strategy for authenticating with Open Humans using the OAuth 2.0 API.

This module lets you authenticate using Open Humans in your Node.js applications. By plugging into Passport, Open Humans authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Installation

$ npm install --save passport-open-humans

Usage

Configure Strategy

The Open Humans authentication strategy authenticates users using a Open Humans account and OAuth 2.0 tokens. The strategy requires a verify callback, which accepts these credentials and calls done providing a user, as well as options specifying a app ID, app secret, and callback URL.

passport.use(new OpenHumansStrategy({
    clientID: OPEN_HUMANS_APP_ID,
    clientSecret: OPEN_HUMANS_APP_SECRET,
    callbackURL: "http://localhost:3000/auth/open-humans/callback"
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ openHumansId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

Use passport.authenticate(), specifying the 'open-humans' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/auth/open-humans/callback', passport.authenticate('open-humans', {
  failureRedirect: '/login',
  successReturnToOrRedirect: '/'
}));
 
app.get('/auth/open-humans', passport.authenticate('open-humans'));

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 5.2.0
    0
    • latest

Version History

Package Sidebar

Install

npm i passport-open-humans

Weekly Downloads

0

Version

5.2.0

License

MIT

Last publish

Collaborators

  • beaugunderson