Skip to content

Commit d4b4b4e

Browse files
authored
Merge pull request #56 from ab320012/patch-1
moving handle_unauthorized function to options, fixes #57, #29
2 parents d04b792 + 330b171 commit d4b4b4e

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ It's not recommended, but it's possible to add NTLM-Authentication without valid
9191
| `badrequest` | `function` | `function(request, response, next) { response.sendStatus(400); }` | Function to handle HTTP 400 Bad Request. |
9292
| `internalservererror` | `function` | `function(request, response, next) { response.sendStatus(500); }` | Function to handle HTTP 500 Internal Server Error. |
9393
| `forbidden` | `function` | `function(request, response, next) { response.sendStatus(403); }` | Function to handle HTTP 403 Forbidden. |
94+
| `unauthorized` | `function` | `function(request, response, next) { response.statusCode = 401; response.setHeader('WWW-Authenticate', 'NTLM'); response.end(); }` | Function to handle HTTP 401 Unauthorized. |
9495
| `prefix` | `string` | `[express-ntlm]` | The prefix is the first argument passed to the `debug`-function. |
9596
| `debug` | `function` | `function() {}` | Function to log the debug messages. See [logging](#logging) for more details. |
9697
| `domain` | `string` | `undefined` | Default domain if the DomainName-field cannot be parsed. |

lib/express-ntlm.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ module.exports = function(options) {
3232
forbidden: function(request, response, next) {
3333
response.sendStatus(403);
3434
},
35-
35+
unauthorized: function(request, response, next) {
36+
response.statusCode = 401;
37+
response.setHeader('WWW-Authenticate', 'NTLM');
38+
response.end();
39+
},
3640
prefix: '[express-ntlm]',
3741
debug: function() {
3842

@@ -87,12 +91,6 @@ module.exports = function(options) {
8791
return false;
8892
}
8993

90-
function handle_unauthorized(request, response, next) {
91-
response.statusCode = 401;
92-
response.setHeader('WWW-Authenticate', 'NTLM');
93-
response.end();
94-
}
95-
9694
function connect_to_proxy(type1, callback) {
9795
var domain = options.domain,
9896
pdc = options.primarydomaincontroller,
@@ -218,7 +216,7 @@ module.exports = function(options) {
218216

219217
if (!auth_headers) {
220218
options.debug(options.prefix, 'No Authorization header present');
221-
return handle_unauthorized(request, response, next);
219+
return options.unauthorized(request, response, next);
222220
}
223221

224222
var ah_data = decode_http_authorization_header(auth_headers);

0 commit comments

Comments
 (0)