http-auth-passport
v1.0.7
Published
Passport.js integration with http-auth module.
Downloads
3,850
Maintainers
Readme
http-auth-passport
Passport.js integration with http-auth module.
Installation
Via git (or downloaded tarball):
$ git clone git://github.com/http-auth/http-auth-passport.git
Via npm:
$ npm install http-auth-passport
Usage
// Express module.
const express = require("express");
// Authentication module.
const auth = require("http-auth");
const authPassport = require("http-auth-passport");
const basic = auth.basic({
realm: "Simon Area.",
file: __dirname + "/../data/users.htpasswd" // gevorg:gpass, Sarah:testpass
});
// Application setup.
const app = express();
// Passport.
const passport = require("passport");
passport.use(authPassport(basic));
// Setup route.
app.get("/", passport.authenticate("http", { session: false }), (req, res) => {
res.end(`Welcome to private area - ${req.user}!`);
});
// Start server.
app.listen(1337, () => {
// Log URL.
console.log("Server running at http://127.0.0.1:1337/");
});
Running tests
It uses mocha, so just run following command in package directory:
$ npm test
License
The MIT License (MIT)