The purpose of this gist is to demonstrate how to query an Active Directory server for a user's profile from a Node.js application. This sample assumes that you are running Node.js on the Microsoft Windows operating system and will not work for Linux or other platforms. The scenario demonstrated is an Express application running in iisnode with Windows Authentication enabled.
How it works:
- iisnode is configured to return the name of the logged in or impersonated user.
- The Node.js application uses a regular expression to split the domain name from the user name.
- The Node.js application spawns a child .NET process that will query Active Directory for the user profile and will output the user profile as a JSON object to standard output.
- The Node.js application will read the standard output stream and will parse the JSON object.
- The Node.js application will store the user information in the HTTP request object.
Things that you can do once you have the user profile:
- Store the user information in your database so that you don't have to query Active Directory for it.
- Store the user profile information in a cache so that you don't request Active Directory on every request (remember that you're running a child process and there will be a performance hit every time that it runs).