Created
December 16, 2015 23:21
-
-
Save fritzy/c5906e965bbcadabf47e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (server, options, next) { | |
console.log('loading plugin'); | |
server.ext({ | |
type:'onPostAuth', | |
method: function (request, reply) { | |
var req = request.raw.req; | |
var res2 = reply.response | |
var headers = {}; | |
var status = null; | |
var res = { | |
'writeHead': function (resStatus, resHeaders) { | |
console.log('writehead'); | |
}, | |
end: function(pl) { | |
console.log('end', pl); | |
if (status === null) { | |
return reply.continue(); | |
} | |
var response = reply(pl); | |
Object.keys(headers).forEach(function(key) { | |
response.header(key, headers[key]); | |
}); | |
response.code(status); | |
res.finished = true; | |
}, | |
setHeader: function (key, value) { | |
console.log('setHeader', key, value); | |
headers[key] = value | |
}, | |
code: function (code) { | |
console.log('code', code); | |
status = code; | |
}, | |
finished: false | |
}; | |
res.__defineSetter__('statusCode', res.code); | |
var nodeSSPI = require('node-sspi'); | |
var nodeSSPIObj = new nodeSSPI({ | |
authoritative: false, | |
retrieveGroups: true | |
}); | |
console.log('authenticating'); | |
nodeSSPIObj.authenticate(req, res, function(err){ | |
if (!res.finished) { | |
res.end(); | |
} else { | |
reply.continue(); | |
} | |
}); | |
console.log('made it this far'); | |
}}); | |
next(); | |
}; | |
module.exports.attributes = { | |
pkg: require('./package.json') | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment