Skip to content

A Passport authentication strategy using a Central Authentication Service (CAS) server.

Notifications You must be signed in to change notification settings

torontomulibrary/passport-cas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

passport-cas

Passport authentication strategy using a Central Authentication Strategy (CAS) server. Supports CAS protocol versions 1.0, 2.0 and 3.0.

npm install @rula/passport-cas

Configure Strategy

Minimum configuration requires the CAS url and service parameters to be defined.

passport.use(new (require('passport-cas').Strategy) ({
  casUrl: 'http://cas.example.com',
  serviceUrl: `http://localhost:3000'
}, function(req, user, done) {
  User.findOne({username: user.username}, function(err, user) {
    if (err) {
      return done(err);
    }
    if (!user) {
      return done(null, false, {message: "Unknown user'});
    }
    return done(null, user);
  });
}));

Authenticate Requests

Using the Express Passport middleware as an example:

exports.casLogin = function(req, res, next) {
  passport.authenticate('cas', function (err, user, info) {
    if (err) {
      return next(err);
    }

    if (!user) {
      req.session.messages = info.message;
      return res.redirect('/');
    }

    req.logIn(user, function (err) {
      if (err) {
        return next(err);
      }

      req.session.messages = '';
      return res.redirect('/');
    });
  })(req, res, next);
};

About

A Passport authentication strategy using a Central Authentication Service (CAS) server.

Resources

Stars

Watchers

Forks

Packages

No packages published