Socket
Socket
Sign inDemoInstall

passport-custom

Package Overview
Dependencies
1
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    passport-custom

Custom authentication strategy for Passport.


Version published
Weekly downloads
148K
decreased by-26.97%
Maintainers
1
Install size
13.5 kB
Created
Weekly downloads
 

Readme

Source

passport-custom

Build Coverage Status Quality Dependencies Tips

Passport strategy for authenticating with custom logic.

This module lets you authenticate using custom logic in your Node.js applications. It is based on passport-local module by Jared Hanson. By plugging into Passport, custom authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, including Express.

Install

$ npm install passport-custom

Usage

Configure Strategy

The custom authentication strategy authenticates users by custom logic of your choosing. The strategy requires a verify callback, which is where the custom logic goes and calls done providing a user. Note that, req is always passed as the first parameter to the verify callback.

Here is the pseudo code:

import passportCustom from 'passport-custom';
const CustomStrategy = passportCustom.Strategy;

passport.use('strategy-name', new CustomStrategy(
  function(req, callback) {
    // Do your custom user finding logic here, or set to false based on req object
    callback(null, user);
  }
));

And a basic example:

passport.use(new CustomStrategy(
  function(req, done) {
    User.findOne({
      username: req.body.username
    }, function (err, user) {
      done(err, user);
    });
  }
));
Authenticate Requests

Use passport.authenticate(), specifying the 'custom' strategy (or whatever you named the strategy upon registration), to authenticate requests.

For example, as route middleware in an Express application:

app.post('/login',
  passport.authenticate('custom', { failureRedirect: '/login' }),
  function(req, res) {
    res.redirect('/');
  }
);

Tests

$ npm install
$ npm test

Credits

  • Mike Bell

License

The MIT License

Copyright (c) 2014-2015 Mike Bell

Keywords

FAQs

Last updated on 12 Feb 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc