Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Replace deprecated 'Database/AD/LDAP (Active)' endpoint #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/routes/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import ldap from 'ldapjs';
import auth0 from 'auth0';
import logger from '../logger';

export default function(domain, clientId) {
export default function(domain, clientId, clientSecret) {
const client = new auth0.AuthenticationClient({
domain: domain,
clientId: clientId
clientId: clientId,
clientSecret: clientSecret
});

return (req, res, next) => {
Expand All @@ -17,7 +18,7 @@ export default function(domain, clientId) {
return next(new ldap.InvalidDnSyntaxError(`The username '${req.dn.toString()}' does not match 'CN=username,OU=connection'`));
}

client.oauth.signIn({ username: parsedName[1], password: req.credentials, connection: parsedName[2] })
client.oauth.passwordGrant({ username: parsedName[1], password: req.credentials, realm: parsedName[2] })
.then(() => {
logger.info(`Bind success for ${req.dn.toString()}`);
res.end();
Expand Down
7 changes: 6 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ nconf
logger.info('Starting LDAP endpoint for Auth...');

const server = ldap.createServer();
server.bind('', authenticate(nconf.get('AUTH0_DOMAIN'), nconf.get('AUTH0_CLIENT_ID')));
server.bind('', authenticate(
nconf.get('AUTH0_DOMAIN'),
nconf.get('AUTH0_CLIENT_ID'),
nconf.get('AUTH0_CLIENT_SECRET')
));

server.search('', requireAdministrator, search(nconf.get('AUTH0_DOMAIN'), nconf.get('AUTH0_API_TOKEN')));
server.listen(nconf.get('LDAP_PORT'), () => {
logger.info(`LDAP server listening on: ${server.url}`);
Expand Down