Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!req.headers.authorization) {
res.set( 'WWW-Authenticate', 'Negotiate' );
//
console.log('-----response-----');
console.log(res._headers);
res.status(401).send();
} else {
// this code is only for Linux !
var KerberosNative = require('kerberos').Kerberos;
var kerberos = new KerberosNative();
var ActiveDirectory = require('activedirectory');
var ad = new ActiveDirectory({
"url": "ldap://",
"baseDN": "",
"username": "",
"password": ""});
//cut phrase "Negotiate "
var ticket = req.headers.authorization.substring(10);
//init context
kerberos.authGSSServerInit("HTTP", function(err, context) {
//check ticket
kerberos.authGSSServerStep(context, ticket, function(err) {
//in success context contains username
ad.findUser(context.username, function(err, user) {
//get user groups