HTTP NTLM Authentication for Node.js

1.8.13 · maintenance · verified Wed Apr 22

httpntlm is a Node.js library designed to facilitate HTTP NTLM authentication, a protocol used in Windows environments. It is a direct port of the Python `python-ntlm` library and notably includes support for NTLMv2, which handles extended security and target information negotiations. The current stable version is 1.8.13, and while it's a mature library with over a decade of history, its release cadence appears infrequent, with the last significant README update in March 2023. Key differentiators include its focused implementation of NTLM for Node.js, offering both a high-level API for common use cases (GET, POST, etc.) and granular access to NTLM message creation and parsing for advanced scenarios. It supports both HTTP and HTTPS connections, and allows for pre-encrypting passwords for enhanced security. The library relies on other modules like `httpreq`, `async`, and `agentkeepalive` for its underlying HTTP requests and flow control.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to perform a basic NTLM-authenticated GET request using the library's high-level API, including error handling and using environment variables for sensitive credentials.

const httpntlm = require('httpntlm');

httpntlm.get({
  url: "https://someurl.com", // Replace with your NTLM-protected URL
  username: process.env.NTLM_USERNAME ?? '',
  password: process.env.NTLM_PASSWORD ?? '',
  workstation: process.env.NTLM_WORKSTATION ?? 'local_workstation',
  domain: process.env.NTLM_DOMAIN ?? ''
}, function (err, res){
  if(err) {
    console.error("NTLM GET request failed:", err.message); // Log the error message
    return;
  }

  console.log("Status Code:", res.statusCode);
  console.log("Response Headers:", res.headers);
  console.log("Response Body (truncated):");
  console.log(res.body ? res.body.substring(0, 500) + '...' : '[No Body]'); // Truncate body for readability
});

view raw JSON →