express-ad-basicauth

2.0.0 • Public • Published

# express-ad-basicauth

Build Status npm (tag) npm GitHub issues Libraries.io dependency status for GitHub repo npm GitHub license

Active directory basic auth middleware for express.

API

Simple usage

const  app  =  require("express")();
const  AdAuth  =  require("express-ad-basicauth");
const port = 8080;
 
AdAuth.initAd(
  {
    url:  "ldap://ad.local:389",
    baseDN:  "dc=ad,dc=local",
    username:  "",
    password:  ""
  },
  null
);
 
app.use(AdAuth.app);
 
app.get("/", (req, res) => {
  res.send("Secret...!");
});
 
app.listen(port, () =>  console.log(`App is listening on port ${port}!`));

Check group membership

const  app  =  require("express")();
const  AdAuth  =  require("express-ad-basicauth");
const port = 8080;
 
AdAuth.initAd(
  {
    url:  "ldap://ad.local:389",
    baseDN:  "dc=ad,dc=local",
    username:  "",
    password:  ""
  },
  "domain-admins"
);
 
app.use(AdAuth.app);
 
app.get("/", (req, res) => {
  res.send("Only for domain admins!");
});
 
app.listen(port, () =>  console.log(`App is listening on port ${port}!`));

Edit / prepare username and / or password

...
AdAuth.editName(user => {
  if (!user.includes("@")) user = `${user}@ad.local`;
  return user;
});
 
AdAuth.editPass(password => {
  password = "Replace the password or do something else here";
  return password;
});
...

To cancel the authentication process with one of the functions simply return false. Then the user will get a 401 code.

Active Directory configuration

Simple config

{
    url:  "ldap://ad.local:389",
    baseDN:  "dc=ad,dc=local",
    username:  "",
    password:  ""
}

Simple Query

{
    url:  "ldap://ad.local:389",
    baseDN:  "dc=ad,dc=local",
    cn: "*Exchange*",
    username:  "",
    password:  ""
}

More Options

For more options visit the activedirectory2 package. You can find it here. All options are available.

Package Sidebar

Install

npm i express-ad-basicauth

Weekly Downloads

7

Version

2.0.0

License

MIT

Unpacked Size

2.3 MB

Total Files

6

Last publish

Collaborators

  • flweber