passport-url

1.0.4 • Public • Published

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('/');
  });

Credits

License

The MIT License

Package Sidebar

Install

npm i passport-url

Weekly Downloads

77

Version

1.0.4

License

none

Last publish

Collaborators

  • freshfruitdigital