Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thisandagain/basic
HTTP Basic Authentication for Node.js
https://github.com/thisandagain/basic
authentication basic-authentication http javascript
Last synced: 18 days ago
JSON representation
HTTP Basic Authentication for Node.js
- Host: GitHub
- URL: https://github.com/thisandagain/basic
- Owner: thisandagain
- License: mit
- Created: 2013-06-25T04:42:34.000Z (over 11 years ago)
- Default Branch: develop
- Last Pushed: 2020-03-20T03:56:16.000Z (over 4 years ago)
- Last Synced: 2024-04-14T12:10:26.620Z (7 months ago)
- Topics: authentication, basic-authentication, http, javascript
- Language: JavaScript
- Homepage:
- Size: 1.65 MB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## basic
#### [HTTP Basic Auth](http://www.ietf.org/rfc/rfc2617.txt) for Node.js[![Build Status](https://travis-ci.org/thisandagain/basic.svg?branch=master)](https://travis-ci.org/thisandagain/basic)
[![Greenkeeper badge](https://badges.greenkeeper.io/thisandagain/basic.svg)](https://greenkeeper.io/)### Installation
```bash
npm install basic
```### Basic Use
```javascript
var http = require('http');
var basic = require('../../lib/index');var auth = basic(function (user, pass, callback) {
if (user === 'let' && pass === 'me in') return callback(null);
callback(401);
});http.createServer(function (req, res) {
auth(req, res, function (err) {
var head = (err) ? {'WWW-Authenticate': 'Basic realm="Secure Area"'} : {};
res.writeHead(err || 200, head);
res.end();
});
}).listen(8000);
``````bash
curl --head -H "Authorization:Basic bGV0Om1lIGlu" http://localhost:8000
```### Testing
```bash
npm test
```