I am new to nodejs and working on a proof of concept just for fun.
Background: I have a cloud directory of user information (like username, password and other info). This cloud directory can be used to authenticate a user only via restful API (i.e. no direct connectivity using LDAP or JDBC etc.).
Aim: To build an LDAP interface for this cloud directory. To start with I am interested only in authentication (LDAP bind).
Intended Flow:
-
LDAPClient initiates a standard LDAP simple BIND request: Host: host where my nodejs app will run Port: 1389 (port that my nodejs app will be bound to) Username: a user from cloud directory Password: user's password
-
This request is received by my NodeJS app (I am using ldapjs module).
// process ldap bind operation myLdapServer.bind(searchBase, function (bindReq, bindRes, next) { // bind creds var userDn = req.dn.toString(); var userPw = req.credentials; console.log('bind DN: ' + req.dn.toString()); ... ... }
-
Within the above callback, I must use http.request to fire a restful API (POST) to the cloud directory with the details I received from the BIND request (i.e. username, password).
-
If restful api response status is 200 (auth success), then I must return success to the LDAPClient, else I must return invalid credentials error.
Success:
bindRes.end();
return next();
Failure:
Console.log("returning error");
return next(new ldap.InvalidCredentialsError());
Questions:
Is this possible using NodeJS? Asking because of the nesting involved as evident above (calling of REST API from within a callback). Also since this is an authentication operation, this is meant to be a blocking operation(?)
Thanks, Jatin
via Jatin
No comments:
Post a Comment