-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# passport-cas | ||
|
||
Cas authentication strategies for Passport. | ||
|
||
|
||
## Install | ||
|
||
$ npm install passport-cas | ||
|
||
#### Configure Strategy | ||
|
||
passport.use(new (require('passport-cas').Strategy)({ | ||
ssoBaseURL: 'http://www.example.com/', | ||
serverBaseURL: 'http://localhost:3000' | ||
}, function(login, done) { | ||
User.findOne({login: login}, function (err, user) { | ||
if (err) { | ||
return done(err); | ||
} | ||
if (!user) { | ||
return done(null, false, {message: 'Unknown user'}); | ||
} | ||
return done(null, user); | ||
}); | ||
})); | ||
|
||
#### Authenticate Requests | ||
|
||
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('/'); | ||
}); | ||
}) | ||
|
||
For example: | ||
|
||
// GET: '/cas_login' | ||
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); | ||
}; | ||
|
||
## License | ||
|
||
[The MIT License](http://opensource.org/licenses/MIT) |