Created
June 2, 2022 07:51
-
-
Save Avi-E-Koenig/6030cef89b909ad906cfd790dca87c8c to your computer and use it in GitHub Desktop.
Active Directory Playground
This file contains hidden or 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
var ActiveDirectory = require('activedirectory'); | |
var config = { | |
url: process.env.AD_URL, | |
baseDN: process.env.AD_BASE_DN, | |
username: process.env.AD_USERNAME, | |
password: process.env.AD_PASSWORD | |
} | |
var ad = new ActiveDirectory(config); | |
ad.authenticate(user.name, user.password, function (err, auth) { | |
if (err) { | |
console.log("๐ ~ file: index.js ~ line 15 ~ err", err) | |
console.log('ERROR: ' + JSON.stringify(err)); | |
return; | |
} | |
if (auth) { | |
console.log("๐ ~ file: index.js ~ line 20 ~ auth", auth) | |
console.log('Authenticated!'); | |
const groupName = '{somegroup}' | |
// InformationSecurity | |
ad.groupExists(groupName, function (err, exists) { | |
if (err) { | |
console.log('ERROR: ' + JSON.stringify(err)); | |
return; | |
} | |
console.log(groupName + '-> exists: ' + exists); | |
}); | |
const username = '{someuser}'; | |
ad.userExists(username, function (err, exists) { | |
if (err) { | |
console.log('ERROR: ' + JSON.stringify(err)); | |
return; | |
} | |
console.log(username + ' exists: ' + exists); | |
}); | |
ad.getGroupMembershipForUser(user.name, function (err, groups) { | |
if (err) { | |
console.log('ERROR: ' + JSON.stringify(err)); | |
return; | |
} | |
if (!groups) console.log('User: ' + user.name + ' not found.'); | |
else console.log(groups); | |
}); | |
} | |
else { | |
console.log('Authentication failed!'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment