When using node.js as a client, is it possible to connect to a server using Windows integrated authentication (e.g. when connecting to IIS)?
My searches for this only turn up results where node.js is used as a server.
When using node.js as a client, is it possible to connect to a server using Windows integrated authentication (e.g. when connecting to IIS)?
My searches for this only turn up results where node.js is used as a server.
Update: There are now some modules that implement Windows-integrated authentication. node-sspi uses SSPI (the Windows security API) to handle the server side of things, but does not do client auth. There are several client implementations such as http-ntlm, but they are not truly integrated since they require the user password -- they do not use SSPI to do transparent auth.
"Windows integrated authentication" is what's known as NTLM authentication. When you receive a HTTP 401 from IIS with a
WWW-Authenticate
header containingNTLM
, you now have the fun of implementing the NTLM authentication protocol. Quoting from this document about the NTLM authentication protocol:The client requests a protected resource from the server:
The server responds with a
401
status, indicating that the client must authenticate.NTLM
is presented as a supported authentication mechanism via theWWW-Authenticate
header. Typically, the server closes the connection at this time:Note that Internet Explorer will only select NTLM if it is the first mechanism offered; this is at odds with RFC 2616, which states that the client must select the strongest supported authentication scheme.
The client resubmits the request with an
Authorization
header containing a Type 1 message parameter. The Type 1 message is Base-64 encoded for transmission. From this point forward, the connection is kept open; closing the connection requires reauthentication of subsequent requests. This implies that the server and client must support persistent connections, via either the HTTP 1.0-style "Keep-Alive" header or HTTP 1.1 (in which persistent connections are employed by default). The relevant request headers appear as follows:The server replies with a
401
status containing a Type 2 message in theWWW-Authenticate
header (again, Base-64 encoded). This is shown below.The client responds to the Type 2 message by resubmitting the request with an
Authorization
header containing a Base-64 encoded Type 3 message:Finally, the server validates the responses in the client's Type 3 message and allows access to the resource.
You'll have to figure out how you'll reply to the Type 2 message's challenge, where the user's password is MD4 hashed and used to create DES keys to encrypt the challenge data.
I'm not sure how you'd get access to the logged in user's credential data which would allow you to accomplish this, though I'm sure it would involve writing a native C++ addon so you could talk to the necessary Windows API. Or, I suppose you could just ask for the user's password.
Alternatively, you could proxy your Node requests through software that handles the NTLM mess for you.
For client side, what works is to use node-libcurl to do REST / HTTP calls.
here's sample code:
For Kerberos:
node-sspi
passport-negotiate
For NTLM
node-sspi
ntlm
ntlm-auth
passport-ntlm
I chose passport-negotiate for Kerberos and express-ntlm for NTLM