-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.js
64 lines (60 loc) · 1.67 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var fs = require('fs'),
path = require('path');
var binding;
// Look for binary for this platform
var nodeV = 'node-' + /[0-9]+\.[0-9]+/.exec(process.versions.node)[0];
var nodeVM = 'node-' + /[0-9]+/.exec(process.versions.node)[0];
var modPath = path.join(__dirname, 'bin', process.platform + '-' + process.arch + '-' + nodeV, 'nodeSSPI');
try {
try{
fs.statSync(modPath + '.node');
}
catch(ex){
modPath = path.join(__dirname, 'bin', process.platform + '-' + process.arch + '-' + nodeVM, 'nodeSSPI');
fs.statSync(modPath + '.node');
}
binding = require(modPath);
}
catch (ex) {
binding = require('bindings')('nodeSSPI');
}
/*
opts:{
offerSSPI: true|false,
offerBasic: true|false,
authoritative: true|false,
perRequestAuth: false|true,
retrieveGroups: false|true, // whether to retrieve groups upon successful auth
maxLoginAttemptsPerConnection: 3,
sspiPackagesUsed: ['NTLM'], // SSPI packages used
domain: <string>, // used by basic authentication
}
*/
function main(opts) {
opts = opts || {};
// defaults
var defaultOpts = {
offerSSPI: true,
offerBasic: true,
authoritative: true,
perRequestAuth: false,
retrieveGroups: false,
maxLoginAttemptsPerConnection: 3,
sspiPackagesUsed: ['NTLM']
};
opts.__proto__ = defaultOpts;
this.opts = opts;
}
main.prototype.authenticate = function (req, res, cb) {
if (typeof cb !== 'function') {
res.statusCode = 500;
res.end('missing callback');
}
if (this.opts.perRequestAuth) {
delete req.connection.user;
delete req.connection.userSid;
delete req.connection.userGroups;
}
binding.authenticate(this.opts, req, res, cb);
}
module.exports = main;