Axios NTLM Authentication Helper
axios-ntlm is a helper library designed to integrate NTLM (NT LAN Manager) authentication into the popular Axios HTTP client, specifically for Node.js environments. It achieves this by attaching interceptors to an Axios instance, allowing seamless NTLM authentication for resources that require it. The current stable version is `1.4.6`. The package generally maintains a moderate release cadence, primarily focusing on dependency updates, bug fixes, and minor enhancements. Its key differentiator lies in its direct integration with Axios, providing a familiar API for developers already using Axios, and simplifying the often complex process of NTLM authentication in JavaScript applications interacting with Windows-authenticated services. It is particularly useful in enterprise settings where NTLM remains prevalent.
Common errors
-
Request hangs indefinitely with no response or error.
cause In versions prior to `1.4.1`, setting an `X-retry` header to `false` could trigger an infinite retry loop, causing requests to never complete and your application to appear unresponsive.fixUpgrade your `axios-ntlm` package to version `1.4.1` or higher. If an upgrade is not immediately possible, avoid sending `X-retry: false` headers when making requests.
Warnings
- breaking A critical security vulnerability (CVE-2022-0155) related to an underlying dependency was patched in version `1.2.2`.
- breaking Prior to `v1.4.1`, requests involving an `X-retry: false` header could inadvertently enter an infinite retry loop, leading to resource exhaustion or indefinite hangs.
- gotcha When providing a custom `AxiosRequestConfig` to `NtlmClient`, explicitly configure `httpAgent` and `httpsAgent` for connection pooling and keep-alive if you are overriding the default agents. The library will add agents if none are present, but your custom configuration might override this.
Install
-
npm install axios-ntlm -
yarn add axios-ntlm -
pnpm add axios-ntlm
Imports
- NtlmClient
const NtlmClient = require('axios-ntlm').NtlmClient;import { NtlmClient } from 'axios-ntlm'; - NtlmCredentials
import NtlmCredentials from 'axios-ntlm';
import { NtlmCredentials } from 'axios-ntlm'; - AxiosRequestConfig
import { AxiosRequestConfig } from 'axios-ntlm';import { AxiosRequestConfig } from 'axios';
Quickstart
import { NtlmClient } from 'axios-ntlm';
(async () => {
let credentials = {
username: 'username',
password: "password",
domain: 'domain'
};
let client = NtlmClient(credentials);
try {
let resp = await client({
url: 'https://protected.site.example.com',
method: 'get'
});
console.log(resp.data);
}
catch (err) {
console.log(err);
console.log("Failed");
}
})();