LDAP user service for cnpmjs.org
$ npm install cnpm-ldap-user-service --save
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
})
};
new LdapUserService(ldapConfig, userMapper)
Returns: instance of LdapUserService
Arguments
ldapConfig
: (required) pass theLdapAuth
Config ObjectuserMapper
: (optional) custom user mapper function
By default, internal userMapper
bind three properties like below.
login
property is bound touid
attributeemail
property is bound tomail
attributename
property is bound todisplayName
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
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue