NextAuth.js provides the ability to setup a custom Credential provider which we can take advantage of to authenticate users against an existing LDAP server.
You will need an additional dependency,
ldapjs, which you can install by running
npm install ldapjs.
Then you must setup the
Providers.Credentials() provider key like so:
The idea is that once one is authenticated with the LDAP server, one can pass through both the username/DN and password to the JWT stored in the browser.
This is then passed back to any API routes and retrieved as such:
Thanks to Winwardo for the code example