passport-url
v1.0.4
Published
Url authentication strategy for Passport.
Downloads
195
Maintainers
Readme
passport-url
Passport strategy for authenticating by url.
Install
$ npm install passport-url
Usage
Configure Strategy
The url authentication strategy authenticates users using an url hash.
The strategy requires a verify
callback, which accepts these
credentials and calls done
providing a user.
passport.use(new UrlStrategy(
function(url, done) {
User.findOne({ hash: url }, function (err, user) {
if (err) { return done(err); }
if (!user) { return done(null, false); }
return done(null, user);
});
}
));
Authenticate Requests
Use passport.authenticate()
, specifying the 'url'
strategy, to
authenticate requests.
For example, as route middleware in an Express application:
// :url contains the hash
app.get('/login/:url',
passport.authenticate('url', { failureRedirect: '/login' }),
function(req, res) {
res.redirect('/');
});