Skip to content

Commit 3a369e4

Browse files
committed
updated README for version 2.0.0
1 parent 268877c commit 3a369e4

File tree

1 file changed

+60
-11
lines changed

1 file changed

+60
-11
lines changed

README.md

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,74 @@
11
# express-ntlm
22

3-
an express middleware to have basic NTLM-authentication in node.js.
3+
An express middleware to have basic NTLM-authentication in node.js.
4+
5+
> **Upgrading from 1.0:** As of v2.0.0 `express-ntlm` requires [`express-session`](https://github.com/expressjs/session). Also the fields for username, domain and workstation have different names now.
6+
7+
*Active Directory support is heavily inspired by [PyAuthenNTLM2](https://github.com/Legrandin/PyAuthenNTLM2/).*
48

59
## install
610

711
$ npm install express-ntlm
812

9-
## usage
13+
## example usage
14+
15+
var express = require('express'),
16+
ntlm = require('./lib/express-ntlm'),
17+
session = require('express-session');
1018

11-
var express = require('express');
1219
var app = express();
13-
var ntlm = require('express-ntlm');
14-
15-
app.all('*', ntlm()); // authenticate for all paths
16-
17-
app.get('/', function(request, response) {
18-
response.send(request.ntlm); // { target: 'MYDOMAIN', userid: 'MYUSERID', workstation: 'MYWORKSTATION' }
20+
21+
// express-ntlm requires a session to store its connection
22+
app.use(session({
23+
secret: 'ntlm-secret',
24+
resave: true,
25+
saveUninitialized: true
26+
}));
27+
28+
app.use(ntlm({
29+
debug: function() {
30+
var args = Array.prototype.slice.apply(arguments);
31+
console.log.apply(null, args);
32+
},
33+
domain: 'MYDOMAIN',
34+
domaincontroller: 'ldap://myad.example',
35+
}));
36+
37+
app.all('*', function(request, response) {
38+
response.end(JSON.stringify(request.ntlm)); // {"DomainName":"MYDOMAIN","UserName":"MYUSER","Workstation":"MYWORKSTATION"}
1939
});
40+
41+
app.listen(80);
42+
43+
## options
44+
45+
| Name | type | default | description |
46+
|------|------|---------|-------------|
47+
| `badrequest` | `function` | `function(request, response, next) { response.sendStatus(400); }` | Function to handle HTTP 400 Bad Request. |
48+
| `internalservererror` | `function` | `function(request, response, next) { response.sendStatus(500); }` | Function to handle 500 Internal Server Error. |
49+
| `forbidden` | `function` | `function(request, response, next) { response.sendStatus(403); }` | Function to handle HTTP 403 Forbidden. |
50+
| `prefix` | `string` | `[express-ntlm]` | The prefix is the first argument passed to the `debug`-function. |
51+
| `debug` | `function` | `function() {}` | Function to log the debug messages. See [logging](#logging) for more details. |
52+
| `domain` | `string` | `undefined` | Default domain if the DomainName-field cannot be parsed. |
53+
| `domaincontroller` | `null` / `string` / `array` | `null` | One or more domaincontroller(s) to handle the authentication. If `null` is specified the user is not validated. |
54+
55+
<a name="logging" />
56+
## logging (examples)
57+
58+
### simple debugging to the console
59+
60+
function() {
61+
var args = Array.prototype.slice.apply(arguments);
62+
console.log.apply(null, args);
63+
}
2064

21-
app.listen(3000);
22-
65+
### logging to [debug](https://github.com/visionmedia/debug)
66+
67+
function() {
68+
var args = Array.prototype.slice.apply(arguments);
69+
debug.apply(null, args.slice(1)); // slice the prefix away, since debug is already prefixed
70+
}
71+
2372
### notes
2473

2574
ntlm is also available within `response.locals` which means you can access it through your template engine (e.g. jade or ejs) using `ntlm`.

0 commit comments

Comments
 (0)