{"library":"node-ntlm-client","title":"Node.js NTLM Client (Legacy)","description":"This package, `node-ntlm-client` at version 0.1.2, provides a client-side implementation for NTLM and NTLMv2 authentication in Node.js environments. It exposes functions for generating NTLM Type 1 and Type 3 messages, and decoding Type 2 messages, enabling developers to implement the NTLM handshake manually. It also includes a `request` convenience function that relies on the now-deprecated `request` HTTP client library. This package has seen no updates in approximately ten years and is considered abandoned, making it unsuitable for new projects. Modern alternatives typically use native Node.js `http`/`https` modules or other maintained HTTP clients, often with fewer external dependencies and better support for contemporary Node.js versions and language features like ESM.","language":"javascript","status":"abandoned","last_verified":"Thu Apr 23","install":{"commands":["npm install node-ntlm-client"],"cli":null},"imports":["const { createType1Message } = require('ntlm-client');","const { decodeType2Message } = require('ntlm-client');","const { createType3Message } = require('ntlm-client');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const { createType1Message, decodeType2Message, createType3Message } = require('ntlm-client');\nconst http = require('http'); // Using native http for demonstration\n\nconst NTLM_SERVER_URL = process.env.NTLM_SERVER_URL ?? 'http://localhost:8080/protected';\nconst USERNAME = process.env.NTLM_USERNAME ?? 'user';\nconst PASSWORD = process.env.NTLM_PASSWORD ?? 'pass';\nconst WORKSTATION = process.env.NTLM_WORKSTATION ?? require('os').hostname();\nconst DOMAIN = process.env.NTLM_DOMAIN ?? '';\n\nasync function performNtlmHandshake() {\n  let type1Msg = createType1Message(WORKSTATION, DOMAIN);\n  console.log('Sending Type 1 message...');\n\n  // Step 1: Send Type 1 message\n  let response1 = await sendHttpRequest(NTLM_SERVER_URL, 'GET', { 'Authorization': `NTLM ${type1Msg}` });\n\n  if (response1.statusCode === 401 && response1.headers['www-authenticate']) {\n    const wwwAuthenticateHeader = response1.headers['www-authenticate'];\n    const type2Match = wwwAuthenticateHeader.match(/NTLM (.*)$/);\n\n    if (type2Match && type2Match[1]) {\n      console.log('Received Type 2 message. Decoding...');\n      let type2Msg = decodeType2Message(type2Match[1]);\n      let type3Msg = createType3Message(type2Msg, USERNAME, PASSWORD, WORKSTATION, DOMAIN);\n      console.log('Sending Type 3 message...');\n\n      // Step 2: Send Type 3 message\n      let response2 = await sendHttpRequest(NTLM_SERVER_URL, 'GET', { 'Authorization': `NTLM ${type3Msg}` });\n\n      if (response2.statusCode === 200) {\n        console.log('NTLM authentication successful!');\n        console.log('Response body:', response2.body.toString().substring(0, 100) + '...');\n      } else {\n        console.error('NTLM authentication failed at Type 3 stage. Status:', response2.statusCode);\n      }\n    } else {\n      console.error('No NTLM Type 2 message found in WWW-Authenticate header.');\n    }\n  } else if (response1.statusCode === 200) {\n    console.log('No NTLM authentication required. Request successful.');\n    console.log('Response body:', response1.body.toString().substring(0, 100) + '...');\n  } else {\n    console.error('Initial request failed or NTLM not initiated. Status:', response1.statusCode);\n  }\n}\n\nfunction sendHttpRequest(url, method, headers) {\n  return new Promise((resolve, reject) => {\n    const client = http.request(url, { method, headers }, (res) => {\n      let body = [];\n      res.on('data', (chunk) => body.push(chunk));\n      res.on('end', () => {\n        resolve({ statusCode: res.statusCode, headers: res.headers, body: Buffer.concat(body) });\n      });\n    });\n    client.on('error', reject);\n    client.end();\n  });\n}\n\nperformNtlmHandshake().catch(console.error);","lang":"javascript","description":"This example demonstrates a conceptual NTLM Type 1, Type 2, and Type 3 message exchange using the core functions, simulating interaction with an NTLM-protected server using native Node.js `http` module. Set NTLM_SERVER_URL, NTLM_USERNAME, NTLM_PASSWORD environment variables for a real NTLM server.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}