npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-passport

v1.0.3

Published

Minimal implementation of the PassportJS interface

Downloads

2

Readme

simple-passport build status

A minimal implementation of the core Passport interface to allow usage of Passport strategy modules.

Motivation

Passport does a lot of things that I don't want or need:

I've also felt an inversion-of-control problem, where Passport takes over control flow and makes it difficult to follow execution.

This module is the minimal subset of Passport that I do want and need. The result is just enough to provide the expected interface to strategy modules.

Disclaimer: This module is not battle-hardened and may not work with all strategy modules.

Usage

This module provides an authenticate() function that is similar to the regular passport.authenticate() function (provides an entry point into strategy modules), but with a slightly different interface.

You don't need to register strategies or use middleware. authenticate() is a normal async function that takes inputs and calls a callback with whether the authentication succeeded. It's up to the application to perform necessary logic in the callback (e.g., set req.user).

Example

var passport = require("simple-passport");
var BasicStrategy = require("passport-http").BasicStrategy;
var http = require("http");

var strategy = new BasicStrategy(function(userid, password, callback) {
  callback(null, userid === "foo" && password === "bar");
});

http.createServer(function(req, res) {
  // Authenticate using http basic access authentication
  passport.authenticate(req, res, strategy, function(err, authed) {
    if ( ! authed) {
      res.statusCode = 403;
      res.end("Forbidden");
    }
    else {
      // Authenticated!
      // ...
    }
  });
}).listen();

API

var passport = require("simple-passport");
passport.authenticate(req, res, strategy, [options,] callback)

Perform authentication using the given strategy object and call the callback with the result. This is similar to using the regular passport.authenticate() function with a "custom callback".

  • req: The current http request, some strategies read headers, etc.
  • res: The current http response, some strategies call res.redirect(), etc.
  • strategy: The strategy object to use
  • options: Passed to the strategy object's .authenticate() function (optional, depends on the strategy)
  • callback: See below
callback(err, result, info, status)

The callback is later called with the result of the strategy, except for when a strategy calls for a redirect.

  • err: An error if one occurred
  • result: Result from the strategy (depends on the strategy, sometimes a "user object", sometimes a boolean indicating success); falsey if authentication failed
  • info: Some strategies return additional data
  • status: Some strategies return a status code