passport-nus-openid

0.0.3 • Public • Published

Passport-NUS-OpenID

Passport strategy for authenticating with NUS using OpenID 2.0.

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

Install

$ npm install passport-nus-openid

Usage

Configure Strategy

The NUS authentication strategy authenticates users using an NUSNET account, which is also an OpenID 2.0 identifier. The strategy requires a verify callback, which accepts this identifier and calls done providing a user. Additionally, options can be supplied to specify a return URL and realm.

passport.use(new NusStrategy({
    returnURL: 'http://localhost:3000/auth/nus/return',
    realm: 'http://localhost:3000/'
  },
  function(identifier, done) {
    User.findByOpenID({ openId: identifier }, function (err, user) {
      return done(err, user);
    });
  }
));

Authenticate Requests

Use passport.authenticate(), specifying the 'NUS' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/auth/nus',
  passport.authenticate('nus'));

app.get('/auth/nus/return', 
  passport.authenticate('nus', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });

Credits

License

The MIT License

Package Sidebar

Install

npm i passport-nus-openid

Weekly Downloads

2

Version

0.0.3

License

none

Last publish

Collaborators

  • lauweijie