Socket
Socket
Sign inDemoInstall

express-basic-auth

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-basic-auth - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

2

package.json
{
"name": "express-basic-auth",
"version": "0.1.2",
"version": "0.1.3",
"description": "Plug & play basic auth middleware for express",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -9,3 +9,5 @@ # express-basic-auth

npm install express-basic-auth
```shell
npm install express-basic-auth
```

@@ -19,8 +21,10 @@ add the `--save` option to add it to the `dependencies` in your `package.json` as well

var app = require('express')();
var basicAuth = require('express-basic-auth');
```js
var app = require('express')();
var basicAuth = require('express-basic-auth');
app.use(basicAuth({
users: { 'admin': 'supersecret' }
}));
app.use(basicAuth({
users: { 'admin': 'supersecret' }
}));
```

@@ -43,9 +47,11 @@ The middleware will now check incoming requests to match the credentials

app.use(basicAuth({
users: {
'admin': 'supersecret',
'adam': 'password1234',
'eve': 'asdfghjkl'
}
}));
```js
app.use(basicAuth({
users: {
'admin': 'supersecret',
'adam': 'password1234',
'eve': 'asdfghjkl'
}
}));
```

@@ -61,7 +67,9 @@ The middleware will check incoming requests to have a basic auth header matching

app.use(basicAuth( { authorizer: myAuthorizer } ));
```js
app.use(basicAuth( { authorizer: myAuthorizer } ));
function myAuthorizer(username, password) {
return username.startsWith('A') && password.startsWith('secret');
}
function myAuthorizer(username, password) {
return username.startsWith('A') && password.startsWith('secret');
}
```

@@ -81,13 +89,15 @@ This will authorize all requests with credentials where the username begins with

app.use(basicAuth({
authorizer: myAsyncAuthorizer,
authorizeAsync: true
}));
```js
app.use(basicAuth({
authorizer: myAsyncAuthorizer,
authorizeAsync: true
}));
function myAsyncAuthorizer(username, password, cb) {
if(username.startsWith('A') && password.startsWith('secret'))
return cb(null, true);
else
return cb(null, false)
}
function myAsyncAuthorizer(username, password, cb) {
if(username.startsWith('A') && password.startsWith('secret'))
return cb(null, true);
else
return cb(null, false)
}
```

@@ -101,6 +111,8 @@ ### Challenge

app.use(basicAuth({
users: { 'someuser': 'somepassword' },
challenge: true
}));
```js
app.use(basicAuth({
users: { 'someuser': 'somepassword' },
challenge: true
}));
```

@@ -112,4 +124,6 @@ ## Try it

npm install express express-basic-auth
node example.js
```shell
npm install express express-basic-auth
node example.js
```

@@ -116,0 +130,0 @@ This will start a small express server listening at port 8080. Just look at the file,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc