Giter Site home page Giter Site logo

express-ldap2rest's Introduction

express-ldap2rest

LDAP to RESP middleware for expressjs based on ldapjs

Features

  • Both ldap & ldaps
  • Authentication by DN
  • Token to avoid password resubmission
  • Entry browsing with filter and scope
  • Entry renaming
  • Entry deleting
  • Attribut adding, replacement and deleting

How to use

  • npm install express-ldap2rest express body-parser cookie-parser
  • Create a server.js file like :
var express = require('express'),
	app = express(),
	middleware = require('express-ldap2rest'),
	bodyParser = require('body-parser'),
	cookieParser = require('cookie-parser')
;

middleware.passphrase = 'StrongPassword';
middleware.config = {
  url: 'ldaps://ldap.exemple.com/',
  options: { rejectUnauthorized: false }
};
middleware.tokenTimeout = 3600;

app.use(bodyParser.json());
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static('static'));
app.use('/v1', middleware.handleReq);

app.listen(3000, function () {
  console.log('Listening on port 3000!');
});

  • Run node server.js

Request it

Authenticate (if needed by your LDAP policies)

  • curl 'http://127.0.0.1:3000/v1' --data-urlencode 'dn=cn=admin,dc=exemple,dc=com' --data-urlencode 'credential=MyPassword' It will return a token

Browse your LDAP

  • Without auth: curl http://localhost:3000/v1/dc=exemple,dc=com
  • With auth: curl http://localhost:3000/v1/dc=exemple,dc=com?auth=<your_token> (auth param may be passed as cookie instead as GET param)
  • Change scope (base by default): curl http://localhost:3000/v1/dc=exemple,dc=com/sub
  • Select only some attributes: curl http://localhost:3000/v1/dc=exemple,dc=com/cn,mail
  • Filter:
    • curl http://localhost:3000/v1/dc=exemple,dc=com/cn=jo*
    • curl http://localhost:3000/v1/dc=exemple,dc=com/(|(cn=jo*)(cn=ba*))
  • Combine scope, filter and attributes: curl http://localhost:3000/v1/dc=exemple,dc=com/sub/cn,mail/(|(cn=jo*)(cn=ba*))

Add a new entry

  • Url: /v1
  • Method: PUT
  • data:
{
  "command": "add",
  "datas": {
   	"objectclass": "users",
    "mail": "[email protected]",
    "givenName": "blah",
    "sn": "blah",
    "uid": "test"
  }
}

Delete entry

  • Url: /v1/dn_to_delete[?auth=]
  • Method: DELETE

Add attribute

  • Url: /v1/dn_to_modify[?auth=]
  • Method: PUT
{
  "command": "modify",
  "actions": {
    "add": {
      "description": "My description"
    }
  }
}

Add non-uniq attribute

  • Url: /v1/dn_to_modify[?auth=]
  • Method: PUT
{
  "command": "modify",
  "actions": {
    "add": {
      "description": ["My first description", "My second description"]
    }
  }
}

Replace attribute

  • Url: /v1/dn_to_modify[?auth=]
  • Method: PUT
{
  "command": "modify",
  "actions": {
    "replace": {
      "description": "My description"
    }
  }
}

Replace non-uniq attribute

  • Url: /v1/dn_to_modify[?auth=]
  • Method: PUT
{
  "command": "modify",
  "actions": {
    "replace": {
      "description": ["My first description", "My second description"]
    }
  }
}

Delete attribute

  • Url: /v1/dn_to_modify[?auth=]
  • Method: PUT
{
  "command": "modify",
  "actions": {
    "delete": {
      "description": "My description"
    }
  }
}

express-ldap2rest's People

Contributors

feraudet avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

adisheshsm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.