Skip to content

lauweijie/passport-nus-openid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Passport-NUS-OpenID

NPM version

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-openid' strategy, to authenticate requests.

For example, as route middleware in an Express application:

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

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

Credits

License

The MIT License

About

NUS OpenID authentication strategy for Passport.

Resources

License

Stars

Watchers

Forks

Packages

No packages published