passport-authorizer

0.0.1 • Public • Published

passport-authorizer

Install

$ npm install passport-authorizer

Usage

passport.use(new AuthorizerStrategy(
  function (authorizer, done) {
    User.findById(authorizer.principalId, function (err, user) {
      if (err) return done(err);
      if (!user) return done(null, false);
      done(err, user);
    });
  }
));

Parameters

By default, AuthorizerStrategy expects to find authorizer in parameters named reqPropKey. If your site prefers to name these fields differently, options are available to change the defaults.

passport.use(new AuthorizerStrategy({
    reqPropKey: 'apiGateway',
    session: false
  },
  function (authorizer, done) {
    // ...
  }
));

When session support is not necessary, it can be safely disabled by setting the session option to false.

The verify callback can be supplied with the request object by setting the passReqToCallback option to true, and changing callback arguments accordingly.

passport.use(new AuthorizerStrategy({
    reqPropKey: 'apiGateway',
    passReqToCallback: true,
    session: false
  },
  function (req, authorizer, done) {
    // request object is now first argument
    // ...
  }
));

Authenticate Requests

app.get('/private', 
  passport.authenticate('authorizer', { session: false }),
  function(req, res) {
    res.json(req.user);
  });

Package Sidebar

Install

npm i passport-authorizer

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

5.68 kB

Total Files

5

Last publish

Collaborators

  • naviapps