@elastic.io/ntlm-client

中文文档
1.0.0发布于 2020/03/06MITCommonJS近 30 天下载 3303

A node.js NTLM client with support for NTLM and NTLMv2 authentication. Continuation of ntlm-client and node-ntlm-client.

原始使用文档

ntlm-client

A node.js NTLM client with support for NTLM and NTLMv2 authentication

npm install ntlm-client

Example Usage

const ntlmRequest = require('@elasticio/ntlm-client').request;

(async function makeExampleRequest() {
  const { response } = await ntlmRequest({
    username: 'MYDOMAIN\SomeUser',
    password: 'P@$$word1!',
    uri: 'https://api.someservice.com',
    method: 'POST',
    request: {
      json: true,   // Example of parameter passed to request.js
      body: {
        foo: 'bar'
      },
      headers: {
        Date: 'Today'
      }
    }
  });
  console.log(`Received status code: ${response.statusCode} Body: ${response.body}`);
})()

API

request(options)

A convenience function that tries to authenticate against a given URL using the request module. If NTLM is not supported, it will fallback to Basic Auth.

  • Arguments
    • options an object holding below options for the authentication process:
      • uri the target URL
      • method the HTTP verb
      • username
      • password
      • request this is optional. An object that holds options that should be passed to the request instance
  • Returns
    • Promise when resolved, the request instance, the result and the response body will be passed

createType1Message([workstation, target])

Creates a type 1 NTLM message to initialize the NTLM handshake

  • Arguments
    • workstation Optional. If undefined, os.hostname() will be used
    • target Optional. This is the domain/host we are trying to authenticate against.
  • Returns
    • string Complete NTLM string that should be sent to the server in the Authentication header

decodeType2Message(str)

Decodes a type 2 message received from the server including the NTLM challenge

  • Arguments
    • str Either the base64 encoded type 2 message, or the complete WWW-Authenticate header, or an object containg the response headers (http.IncomingMessage)
  • Returns
    • type2Message An object containing the following information about the received type 2 message: flags, encoding, version, challenge, targetName, targetInfo.

createType3Message(type2Message, username, password[, workstation, target])

Creates a type 3 message based on the type 2 message received from the server.

  • Arguments
    • type2Message The decoded type 2 message object
    • username
    • password
    • workstation Optional. If falsy, os.hostname() will be used
    • target Optional. If falsy, the target name from the type 2 message will be used. This is the domain/host we are trying to authenticate against.
  • Returns
    • string Complete NTLM string that should be sent to the server in the Authentication header

版本与发布记录

@elastic.io/ntlm-client 共发布 1 个版本,首次发布于 2020/03/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0latest2020/03/066 年前

关于 @elastic.io/ntlm-client 的常见问题

@elastic.io/ntlm-client 是什么?

A node.js NTLM client with support for NTLM and NTLMv2 authentication. Continuation of ntlm-client and node-ntlm-client.

如何安装 @elastic.io/ntlm-client?

在项目目录运行 npm install @elastic.io/ntlm-client,或使用 pnpm add / yarn add / bun add。

@elastic.io/ntlm-client 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/elastic.io__ntlm-client 是否存在。

@elastic.io/ntlm-client 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@elastic.io/ntlm-client 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js 12。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@elastic.io/ntlm-client 可以商用吗?

@elastic.io/ntlm-client 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@elastic.io/ntlm-client 的下载量有多少?

根据 npm 官方下载统计,@elastic.io/ntlm-client 在 2026/10/13 – 2026/11/11 这 30 天内被下载 3,303 次,日均约 110 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@elastic.io/ntlm-client 还在维护吗?

最新版本 1.0.0 发布于 2020/03/06(6 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/03/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。