https://github.com/expressjs/basic-auth-connect
Basic auth middleware for node and connect
https://github.com/expressjs/basic-auth-connect
Last synced: 8 months ago
JSON representation
Basic auth middleware for node and connect
- Host: GitHub
- URL: https://github.com/expressjs/basic-auth-connect
- Owner: expressjs
- License: mit
- Created: 2014-01-08T08:02:40.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2024-09-30T10:15:00.000Z (over 1 year ago)
- Last Synced: 2024-10-29T14:24:26.299Z (about 1 year ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 130
- Watchers: 18
- Forks: 27
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# basic-auth-connect
Connect's Basic Auth middleware in its own module. You should consider to create your own middleware with [basic-auth](https://github.com/visionmedia/node-basic-auth).
## API
```js
var basicAuth = require('basic-auth-connect');
```
Simple username and password
```js
connect()
.use(basicAuth('username', 'password'));
```
Callback verification
```js
connect()
.use(basicAuth(function(user, pass){
return 'tj' == user && 'wahoo' == pass;
}))
```
Async callback verification, accepting `fn(err, user)`.
```js
connect()
.use(basicAuth(function(user, pass, fn){
User.authenticate({ user: user, pass: pass }, fn);
}))
```
**Security Considerations**
Important: When using the callback method, it is recommended to use a time-safe comparison function like [crypto.timingSafeEqual](https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b) to prevent timing attacks.
## License
[MIT](./LICENSE)