cnpm-ldap-user-service

1.0.2 • Public • Published

cnpm-ldap-user-service

LDAP user service for cnpmjs.org

XO code style NPM version NPM download Gittip

Install

$ npm install cnpm-ldap-user-service --save

Example

Set userService on your config/config.js

var LdapUserService = require('cnpm-ldap-user-service');
 
module.exports = {
  // input your custom config here
  admin: {
    'admin': 'admin@cnpmjs.org'
  },
  // enable private mode, only admin can publish, other use just can sync package from source npm
  enablePrivate: false,
 
  // registry scopes, if don't set, means do not support scopes
  scopes: [
    '@lnpm',
  ],
 
  // redirect @cnpm/private-package => private-package
  // forward compatbility for update from lower version cnpmjs.org
  adaptScope: true,
 
  // force user publish with scope
  // but admins still can publish without scope
  forcePublishWithScope: true,
  
  // your ldap user service
  userService: new LdapUserService({
    url: 'ldaps://ldap.example.org:636',
    bindDN: 'uid=myadminusername,ou=users,dc=example,dc=org',
    bindCredentials: 'mypassword',
    searchBase: 'ou=users,dc=example,dc=org',
    searchFilter: '(uid={{username}})',
    reconnect: true
  })  
};

API

new LdapUserService(ldapConfig, userMapper)

Returns: instance of LdapUserService

Arguments

By default, internal userMapper bind three properties like below.

  • login property is bound to uid attribute
  • email property is bound to mail attribute
  • name property is bound to displayName attribute

If you want to change the default, you can pass the userMapper function like below.

var LdapUserService = require('cnpm-ldap-user-service');
 
var config = {
   // input your custom config here
   admins: {
     'admin': 'admin@cnpmjs.org'
   },
   // ...
   userService: new LdapUserService({
     url: 'ldaps://ldap.example.org:636',
     bindDN: 'uid=myadminusername,ou=users,dc=example,dc=org',
     bindCredentials: 'mypassword',
     searchBase: 'ou=users,dc=example,dc=org',
     searchFilter: '(uid={{username}})',
     reconnect: true
   }, (ldapUser) => {
     // TODO: return your own authorization object using `ldapUser`
     // TODO: (https://github.com/cnpm/cnpmjs.org/wiki/Use-Your-Own-User-Authorization)
     return {
       login: ldapUser.uid,
       email: ldapUser.mail,
       name: ldapUser.displayName,
       site_admin: config.admins[ldapUser.uid] === ldapUser.mail
     }
   })  
 };
 
module.exports = config

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i cnpm-ldap-user-service

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • kyungw00k