Skip to content

kyungw00k/cnpm-ldap-user-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cnpm-ldap-user-service

LDAP user service for cnpmjs.org

XO code style NPM version NPM download

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