http-auth
Advanced tools
Comparing version 4.1.1 to 4.1.2
{ | ||
"name": "http-auth", | ||
"description": "Node.js package for HTTP basic and digest access authentication.", | ||
"version": "4.1.1", | ||
"version": "4.1.2", | ||
"author": "Gevorg Harutyunyan (http://github.com/gevorg)", | ||
@@ -6,0 +6,0 @@ "maintainers": [ |
@@ -17,3 +17,3 @@ # http-auth | ||
$ npm install http-auth | ||
``` | ||
``` | ||
@@ -25,4 +25,4 @@ ## Basic example | ||
const basic = auth.basic({ | ||
realm: "Simon Area.", | ||
file: __dirname + "/../data/users.htpasswd" | ||
realm: "Simon Area.", | ||
file: __dirname + "/../data/users.htpasswd" | ||
}); | ||
@@ -32,3 +32,3 @@ | ||
http.createServer(basic.check((req, res) => { | ||
res.end(`Welcome to private area - ${req.user}!`); | ||
res.end(`Welcome to private area - ${req.user}!`); | ||
})).listen(1337); | ||
@@ -38,12 +38,12 @@ | ||
## Custom authentication | ||
```javascript | ||
```javascript | ||
// Authentication module. | ||
const auth = require('http-auth'); | ||
const basic = auth.basic({ | ||
realm: "Simon Area." | ||
}, (username, password, callback) => { | ||
// Custom authentication | ||
// Use callback(error) if you want to throw async error. | ||
callback(username === "Tina" && password === "Bullock"); | ||
} | ||
realm: "Simon Area." | ||
}, (username, password, callback) => { | ||
// Custom authentication | ||
// Use callback(error) if you want to throw async error. | ||
callback(username === "Tina" && password === "Bullock"); | ||
} | ||
); | ||
@@ -53,3 +53,3 @@ | ||
http.createServer(basic.check((req, res) => { | ||
res.end(`Welcome to private area - ${req.user}!`); | ||
res.end(`Welcome to private area - ${req.user}!`); | ||
})).listen(1337); | ||
@@ -67,3 +67,3 @@ ``` | ||
const basic = auth.basic({ | ||
realm: "Simon Area.", | ||
realm: "Simon Area.", | ||
file: __dirname + "/../data/users.htpasswd", // gevorg:gpass, Sarah:testpass | ||
@@ -81,6 +81,6 @@ proxy: true | ||
http.createServer((req, res) => { | ||
res.end("Request successfully proxied!"); | ||
res.end("Request successfully proxied!"); | ||
}).listen(1338, () => { | ||
// Log URL. | ||
console.log("Server running at http://127.0.0.1:1338/"); | ||
// Log URL. | ||
console.log("Server running at http://127.0.0.1:1338/"); | ||
}); | ||
@@ -105,11 +105,11 @@ | ||
basic.on('success', (result, req) => { | ||
console.log(`User authenticated: ${result.user}`); | ||
console.log(`User authenticated: ${result.user}`); | ||
}); | ||
basic.on('fail', (result, req) => { | ||
console.log(`User authentication failed: ${result.user}`); | ||
console.log(`User authentication failed: ${result.user}`); | ||
}); | ||
basic.on('error', (error, req) => { | ||
console.log(`Authentication error: ${error.code + " - " + error.message}`); | ||
console.log(`Authentication error: ${error.code + " - " + error.message}`); | ||
}); | ||
@@ -122,10 +122,10 @@ ``` | ||
- `file` - File where user details are stored. | ||
- Line format is **{user:pass}** or **{user:passHash}** for basic access. | ||
- Line format is **{user:realm:passHash}** for digest access. | ||
- Line format is **{user:pass}** or **{user:passHash}** for basic access. | ||
- Line format is **{user:realm:passHash}** for digest access. | ||
- `algorithm` - Algorithm that will be used only for **digest** access authentication. | ||
- **MD5** by default. | ||
- **MD5-sess** can be set. | ||
- **MD5** by default. | ||
- **MD5-sess** can be set. | ||
- `qop` - Quality of protection that is used only for **digest** access authentication. | ||
- **auth** is set by default. | ||
- **none** this option is disabling protection. | ||
- **auth** is set by default. | ||
- **none** this option is disabling protection. | ||
- `msg401` - Message for failed authentication 401 page. | ||
@@ -132,0 +132,0 @@ - `msg407` - Message for failed authentication 407 page. |
23394