feathers-authentication-ldap
LDAP authentication strategy for feathers-authentication using Passport
Installation
npm install feathers-authentication-ldap --save
Documentation
Usage
In most cases initializing the feathers-authentication-ldap
module is as simple as doing this:
app;app;
This will pull from your global auth
object in your config file.
It will also mix in the following defaults, which should be customized.
Default Options
name: 'ldap' server: url: 'ldap://localhost:389' bindDn: 'cn=anonymous' bindCredentials: '' // bindpw searchBase: 'dc=de' searchFilter: '(uid={{username}})' searchAttributes: null // optional array of props to fetch from ldap passReqToCallback: true
LDAP Verifier class
The Verifier
class has a verify
function that is the passport verify callback. In this module it gets called after LDAP authentication succeeds. By default it does nothing but you can overwrite it to make furthers validation
checks. See examples/app.js.
feathers-authentication-jwt
Usage with To authenticate following requests using the jwt use feathers-authentication-jwt
. This plugin depends on the users
Service to populate the user entity.
To get rid of this dependency and store necessary data in the JWT payload see examples/app.js and examples/app.js.
Asynchronous LDAP Strategy configuration
Per request configuration of the LDAP strategy is supported by taking advantage of the passport-ldapauth asynchronous configuration retrieval feature.
This makes it possible to adjust the LDAP settings based on the authentication request. I.E. An Active Directory server that uses the user's authentication credentials for binding in place of an anonymous user can leverage this feature by setting the server bind credentials to the credentials provided in the authentication request.
To use the asynchronous settings method you include the asyncOptions parameter when configuring the ldap strategy in the authentication service. The asyncOptions parameter should be set to a function that accepts the authentication request object and returns a new object with settings that should be merged into the ldap settings.
Example asyncOptions implementation in authentication service
/*Given the following authentication strategy configuration... "authentication": { "ldap": { "server": { "url": "ldap://<your Active Directory server>/", "searchBase": "cn=users,dc=<your Active Directory domain>,dc=local", "searchFilter": "(|(userPrincipalName={{username}})(sAMAccountName={{username}}))", "searchAttributes": null } }},*/ const authentication = const jwt = const local = const ldap = module { app // user credentials in authentication request used as the server bind credentials in ldap app; app; }
Simple Example
Here's an example of a Feathers server that uses feathers-authentication-ldap
.
const feathers = ;const rest = ;const hooks = ;const bodyParser = ;const errorHandler = ;const errors = ;const auth = ;const ldap = ; // Initialize the applicationconst app = ; // Load configuration, usually done by feathers-configurationapp; app // Configure feathers-authentication with ldap ; // Authenticate the user using the LDAP strategy// and if successful return a JWT.app; app;console;
# Request a token curl -H "Content-Type: application/json" \ -X POST \ -d '{"username":"ldap-user@example.com","password":"admin"}' \ http://localhost:3030/authentication
License
Copyright (c) 2016
Licensed under the MIT license.