https://github.com/http-auth/http-auth-passport
Passport.js integration for http-auth.
https://github.com/http-auth/http-auth-passport
authentication integrations javascript passport passportjs
Last synced: 7 months ago
JSON representation
Passport.js integration for http-auth.
- Host: GitHub
- URL: https://github.com/http-auth/http-auth-passport
- Owner: http-auth
- License: mit
- Created: 2020-02-02T20:53:24.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-16T10:32:55.000Z (over 1 year ago)
- Last Synced: 2024-10-30T13:52:55.343Z (over 1 year ago)
- Topics: authentication, integrations, javascript, passport, passportjs
- Language: JavaScript
- Homepage:
- Size: 309 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# http-auth-passport
[Passport.js](http://www.passportjs.org/) integration with [http-auth](https://github.com/gevorg/http-auth) module.
[](https://github.com/http-auth/http-auth-passport/actions/workflows/build.yml)
## Installation
Via git (or downloaded tarball):
```bash
$ git clone git://github.com/http-auth/http-auth-passport.git
```
Via [npm](http://npmjs.org/):
```bash
$ npm install http-auth-passport
```
## Usage
```javascript
// 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](https://mochajs.org/), so just run following command in package directory:
```bash
$ npm test
```
## License
The MIT License (MIT)