### Basic HTTP GET Request with NTLM Authentication Source: https://github.com/samdecrock/node-http-ntlm/blob/master/README.md Use this snippet for making a basic HTTP GET request with NTLM authentication. Ensure you have the 'httpntlm' library installed. ```javascript var httpntlm = require('httpntlm'); httpntlm.get({ url: "https://someurl.com", username: 'm$', password: 'stinks', workstation: 'choose.something', domain: '' }, function (err, res){ if(err) return console.log(err); console.log(res.headers); console.log(res.body); }); ``` -------------------------------- ### Pre-encrypt Password for NTLM Authentication Source: https://github.com/samdecrock/node-http-ntlm/blob/master/README.md This example demonstrates how to pre-encrypt passwords using NTLM hashing functions before making an HTTP request. This is useful when you have the encrypted password and want to use it directly. ```javascript var httpntlm = require('httpntlm'); var ntlm = httpntlm.ntlm; var lm = ntlm.create_LM_hashed_password('Azx123456'); var nt = ntlm.create_NT_hashed_password('Azx123456'); httpntlm.get({ url: "https://someurl.com", username: 'm$', lm_password: lm, nt_password: nt, workstation: 'choose.something', domain: '' }, function (err, res){ if(err) return console.log(err); console.log(res.headers); console.log(res.body); }); ``` -------------------------------- ### Make GET Request with Custom Headers Source: https://github.com/samdecrock/node-http-ntlm/blob/master/README.md Use this snippet to make a GET request to a URL while passing custom headers. Ensure you have the httpntlm library installed. ```javascript httpntlm.get({ url: "http://localhost:3000", username: 'm$', password: 'stinks', workstation: 'choose.something', domain: 'somedomain', headers: { 'User-Agent': 'my-useragent' } }, function (err, res){ if(err) return console.log(err); console.log(res.headers); console.log(res.body); }); ``` -------------------------------- ### Manual NTLM Authentication Flow with httpreq Source: https://github.com/samdecrock/node-http-ntlm/blob/master/README.md This advanced example shows how to manually handle the NTLM authentication handshake (Type 1, Type 2, Type 3 messages) using the 'httpntlm' library's NTLM functions and the 'httpreq' library for making HTTP requests. It also utilizes 'agentkeepalive' for persistent connections. ```javascript var ntlm = require('httpntlm').ntlm; var async = require('async'); var httpreq = require('httpreq'); var HttpsAgent = require('agentkeepalive').HttpsAgent; var keepaliveAgent = new HttpsAgent(); var options = { url: "https://someurl.com", username: 'm$', password: 'stinks', workstation: 'choose.something', domain: '' }; async.waterfall([ function (callback){ var type1msg = ntlm.createType1Message(options); httpreq.get(options.url, { headers:{ 'Connection' : 'keep-alive', 'Authorization': type1msg }, agent: keepaliveAgent }, callback); }, function (res, callback){ if(!res.headers['www-authenticate']) return callback(new Error('www-authenticate not found on response of second request')); var type2msg = ntlm.parseType2Message(res.headers['www-authenticate']); var type3msg = ntlm.createType3Message(type2msg, options); setImmediate(function() { httpreq.get(options.url, { headers:{ 'Connection' : 'Close', 'Authorization': type3msg }, allowRedirects: false, agent: keepaliveAgent }, callback); }); } ], function (err, res) { if(err) return console.log(err); console.log(res.headers); console.log(res.body); }); ``` -------------------------------- ### Download Binary Files with HTTP NTLM GET Request Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Set `binary: true` to receive the response body as a raw Buffer, suitable for downloading binary files like images or documents. ```javascript var httpntlm = require('httpntlm'); var fs = require('fs'); httpntlm.get({ url: 'http://internal.corp/files/report.xlsx', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP', binary: true }, function (err, res) { if (err) return console.error(err); fs.writeFile('report.xlsx', res.body, function (writeErr) { if (writeErr) return console.error('Write failed:', writeErr); console.log('report.xlsx saved!'); }); }); ``` -------------------------------- ### Send Custom Headers with HTTP NTLM GET Request Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Forward custom headers to the final authenticated request. Note that 'Connection' and 'Authorization' are reserved and ignored. ```javascript var httpntlm = require('httpntlm'); httpntlm.get({ url: 'http://internal.corp/api/data', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP', headers: { 'User-Agent': 'MyApp/1.0', 'X-Request-ID': 'abc-123' // 'Authorization' and 'Connection' are ignored if provided here } }, function (err, res) { if (err) return console.error(err); console.log(res.body); }); ``` -------------------------------- ### httpntlm.get(options, callback) Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Performs an authenticated HTTP GET request to an NTLM-protected endpoint. It handles the NTLM handshake internally and supports all httpreq options along with NTLM credentials. ```APIDOC ## httpntlm.get(options, callback) ### Description Sends a GET request to an NTLM-protected endpoint. Handles the full Type1 → Type2 → Type3 handshake internally. All [httpreq](https://github.com/SamDecrock/node-httpreq) options (custom headers, cookies, timeout, binary mode, etc.) are supported alongside the NTLM credential fields. ### Parameters #### Options Object - **url** (string) - Required - The URL to send the GET request to. - **username** (string) - Required - The username for NTLM authentication. - **password** (string) - Required - The password for NTLM authentication. - **workstation** (string) - Optional - The workstation name (default: ''). - **domain** (string) - Optional - The domain name (default: ''). - **timeout** (number) - Optional - The request timeout in milliseconds. - **headers** (object) - Optional - Custom headers to send with the request. - **cookies** (object) - Optional - Cookies to send with the request. - **binary** (boolean) - Optional - If true, the response body will be a Buffer. ### Callback Function - **err** - An error object if the request failed, otherwise null. - **res** - The response object containing statusCode, headers, and body. ### Request Example ```js var httpntlm = require('httpntlm'); httpntlm.get({ url: 'http://internal.corp/api/data', username: 'jdoe', password: 'P@ssw0rd', workstation: 'MYPC', // optional, default: '' domain: 'CORP', // optional, default: '' timeout: 5000 // optional, milliseconds }, function (err, res) { if (err) return console.error('Request failed:', err.message); console.log('Status:', res.statusCode); console.log('Headers:', res.headers); console.log('Body:', res.body); // => Status: 200 // => Body: {"data": "..."} }); ``` ``` -------------------------------- ### Dispatch Generic HTTP Method with httpntlm Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Use this generic method dispatcher to call any HTTP method by name (e.g., 'get', 'post', 'put', 'patch', 'delete', 'options'). ```javascript var httpntlm = require('httpntlm'); httpntlm.method('get', { url: 'http://internal.corp/report', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP' }, function (err, res) { if (err) return console.error(err); console.log(res.body); }); ``` -------------------------------- ### Perform Authenticated HTTP GET Request with httpntlm Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Use this to send a GET request to an NTLM-protected endpoint. It handles the NTLM handshake and supports all httpreq options. ```javascript var httpntlm = require('httpntlm'); httpntlm.get({ url: 'http://internal.corp/api/data', username: 'jdoe', password: 'P@ssw0rd', workstation: 'MYPC', // optional, default: '' domain: 'CORP', // optional, default: '' timeout: 5000 // optional, milliseconds }, function (err, res) { if (err) return console.error('Request failed:', err.message); console.log('Status:', res.statusCode); console.log('Headers:', res.headers); console.log('Body:', res.body); // => Status: 200 // => Body: {"data": "..."} }); ``` -------------------------------- ### Download Binary Files with NTLM Authentication Source: https://github.com/samdecrock/node-http-ntlm/blob/master/README.md This snippet shows how to download binary files (e.g., spreadsheets) using NTLM authentication. The `binary: true` option is crucial for handling binary data correctly, and the downloaded content is then saved to a local file. ```javascript httpntlm.get({ url: "https://someurl.com/file.xls", username: 'm$', password: 'stinks', workstation: 'choose.something', domain: '', binary: true }, function (err, response) { if(err) return console.log(err); fs.writeFile("file.xls", response.body, function (err) { if(err) return console.log("error writing file"); console.log("file.xls saved!"); }); }); ``` -------------------------------- ### Binary File Downloads Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Enables downloading binary files by setting the `binary` option to `true`, which returns the response body as a raw `Buffer`. ```APIDOC ## httpntlm.get with Binary Option ### Description Download binary files such as images or documents by setting the `binary` option to `true`. The response body will be a `Buffer`. ### Method `httpntlm.get(options, callback)` ### Parameters #### Options - **url** (string) - Required - The URL of the binary file. - **username** (string) - Required - The username for NTLM authentication. - **password** (string) - Required - The password for NTLM authentication. - **domain** (string) - Required - The domain for NTLM authentication. - **binary** (boolean) - Required - Set to `true` to receive the response body as a `Buffer`. ### Request Example ```javascript var httpntlm = require('httpntlm'); var fs = require('fs'); httpntlm.get({ url: 'http://internal.corp/files/report.xlsx', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP', binary: true }, function (err, res) { if (err) return console.error(err); fs.writeFile('report.xlsx', res.body, function (writeErr) { if (writeErr) return console.error('Write failed:', writeErr); console.log('report.xlsx saved!'); }); }); ``` ``` -------------------------------- ### Custom Headers Support Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Demonstrates how to send custom headers with NTLM authenticated requests. Reserved headers like 'Connection' and 'Authorization' are handled internally. ```APIDOC ## httpntlm.get with Custom Headers ### Description Send custom headers with an NTLM authenticated GET request. Headers like 'User-Agent' and 'X-Request-ID' are forwarded to the final request. ### Method `httpntlm.get(options, callback)` ### Parameters #### Options - **url** (string) - Required - The URL to request. - **username** (string) - Required - The username for NTLM authentication. - **password** (string) - Required - The password for NTLM authentication. - **domain** (string) - Required - The domain for NTLM authentication. - **headers** (object) - Optional - An object containing custom headers to send. ### Request Example ```javascript var httpntlm = require('httpntlm'); httpntlm.get({ url: 'http://internal.corp/api/data', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP', headers: { 'User-Agent': 'MyApp/1.0', 'X-Request-ID': 'abc-123' } }, function (err, res) { if (err) return console.error(err); console.log(res.body); }); ``` ``` -------------------------------- ### httpntlm.method(method, options, callback) Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt A generic HTTP method dispatcher that allows calling any HTTP method by name. It powers the verb-specific helpers and accepts the same options and callback structure. ```APIDOC ## httpntlm.method(method, options, callback) ### Description The underlying function that powers all verb-specific helpers. Use this to call any HTTP method by name (`'get'`, `'post'`, `'put'`, `'patch'`, `'delete'`, `'options'`). ### Parameters #### Method - **method** (string) - Required - The HTTP method to use (e.g., 'get', 'post'). #### Options Object - **url** (string) - Required - The URL to send the request to. - **username** (string) - Required - The username for NTLM authentication. - **password** (string) - Required - The password for NTLM authentication. - **domain** (string) - Optional - The domain name (default: ''). - **headers** (object) - Optional - Custom headers to send with the request. - **body** (string) - Optional - The data to send in the request body for methods like POST or PUT. ### Callback Function - **err** - An error object if the request failed, otherwise null. - **res** - The response object containing statusCode, headers, and body. ### Request Example ```js var httpntlm = require('httpntlm'); httpntlm.method('get', { url: 'http://internal.corp/report', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP' }, function (err, res) { if (err) return console.error(err); console.log(res.body); }); ``` ``` -------------------------------- ### httpntlm.post(options, callback) Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Performs an authenticated HTTP POST request with a body to an NTLM-protected endpoint. Body data, content-type, and other httpreq options are passed through to the final authenticated request. ```APIDOC ## httpntlm.post(options, callback) ### Description Sends a POST request with a body to an NTLM-protected endpoint. Body data, content-type, and other httpreq options are passed through to the final authenticated request. ### Parameters #### Options Object - **url** (string) - Required - The URL to send the POST request to. - **username** (string) - Required - The username for NTLM authentication. - **password** (string) - Required - The password for NTLM authentication. - **domain** (string) - Optional - The domain name (default: ''). - **headers** (object) - Required - Headers to send with the request, typically including 'Content-Type'. - **body** (string) - Required - The data to send in the request body. ### Callback Function - **err** - An error object if the request failed, otherwise null. - **res** - The response object containing statusCode and body. ### Request Example ```js var httpntlm = require('httpntlm'); httpntlm.post({ url: 'http://internal.corp/api/items', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'New Item', value: 42 }) }, function (err, res) { if (err) return console.error(err); console.log('Status:', res.statusCode); console.log('Response:', res.body); // => Status: 201 }); ``` ``` -------------------------------- ### Create NTLM Type 1 (Negotiate) Message Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Constructs the base64-encoded NTLM Type 1 negotiation message string. This is sent as the 'Authorization' header in the first handshake request. ```javascript var ntlm = require('httpntlm').ntlm; var type1msg = ntlm.createType1Message({ domain: 'CORP', workstation: 'MYPC' }); console.log(type1msg); // => "NTLM TlRMTVNTUAABAAAAB7IIog..." // Use directly in a custom HTTP request: var httpreq = require('httpreq'); httpreq.get('http://internal.corp/resource', { headers: { 'Connection': 'keep-alive', 'Authorization': type1msg } }, function (err, res) { // Server responds with Type 2 challenge in www-authenticate header console.log(res.headers['www-authenticate']); }); ``` -------------------------------- ### Compute NT Password Hash for NTLM Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Produces the NT hash (MD4 of the UTF-16LE-encoded password) as a Buffer, which is used in NTLMv2 authentication. Useful for pre-computing credentials. ```javascript var httpntlm = require('httpntlm'); var ntlm = httpntlm.ntlm; var ntHash = ntlm.create_NT_hashed_password('Azx123456'); console.log(ntHash); // => httpntlm.get({ url: 'https://internal.corp/api/secure', username: 'jdoe', lm_password: ntlm.create_LM_hashed_password('Azx123456'), nt_password: ntHash, domain: 'CORP' }, function (err, res) { if (err) return console.error(err); console.log(res.statusCode); }); ``` -------------------------------- ### ntlm.create_NT_hashed_password Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Computes the NT hash (MD4 of UTF-16LE encoded password) as a `Buffer`, which is used in NTLMv2 authentication. ```APIDOC ## ntlm.create_NT_hashed_password(password) ### Description Generates the NT hash of a given password. This hash is essential for NTLMv2 authentication and can be used in place of the plaintext password. ### Parameters - **password** (string) - Required - The plaintext password to hash. ### Returns - **Buffer** - The computed NT password hash. ### Usage Example ```javascript var httpntlm = require('httpntlm'); var ntlm = httpntlm.ntlm; var ntHash = ntlm.create_NT_hashed_password('Azx123456'); httpntlm.get({ url: 'https://internal.corp/api/secure', username: 'jdoe', lm_password: ntlm.create_LM_hashed_password('Azx123456'), nt_password: ntHash, domain: 'CORP' }, function (err, res) { if (err) return console.error(err); console.log(res.statusCode); }); ``` ``` -------------------------------- ### httpntlm.put(options, callback) Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Performs an authenticated HTTP PUT request to an NTLM-protected endpoint. Supports standard httpreq options and NTLM credentials. ```APIDOC ## httpntlm.put(options, callback) ### Description Sends a PUT request to an NTLM-protected endpoint. Supports standard httpreq options and NTLM credentials. ### Parameters #### Options Object - **url** (string) - Required - The URL to send the PUT request to. - **username** (string) - Required - The username for NTLM authentication. - **password** (string) - Required - The password for NTLM authentication. - **domain** (string) - Optional - The domain name (default: ''). - **headers** (object) - Optional - Custom headers to send with the request. - **body** (string) - Optional - The data to send in the request body. ### Callback Function - **err** - An error object if the request failed, otherwise null. - **res** - The response object containing statusCode and body. ### Request Example ```js var httpntlm = require('httpntlm'); httpntlm.put({ url: 'http://internal.corp/api/items/1', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'Updated Item' }) }, function (err, res) { if (err) return console.error(err); console.log('Status:', res.statusCode); // => 200 }); ``` ``` -------------------------------- ### ntlm.createType1Message Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Builds the NTLM Type 1 (Negotiate) message, which is a base64-encoded string used in the `Authorization` header for the initial handshake. ```APIDOC ## ntlm.createType1Message(options) ### Description Constructs the NTLM Type 1 message, which is the first step in the NTLM authentication handshake. This message is typically sent in the `Authorization` header. ### Parameters #### Options - **domain** (string) - Optional - The domain name. - **workstation** (string) - Optional - The workstation name. ### Returns - **string** - The base64-encoded NTLM Type 1 message. ### Usage Example ```javascript var ntlm = require('httpntlm').ntlm; var type1msg = ntlm.createType1Message({ domain: 'CORP', workstation: 'MYPC' }); console.log(type1msg); // => "NTLM TlRMTVNTUAABAAAAB7IIog..." // Use directly in a custom HTTP request: var httpreq = require('httpreq'); httpreq.get('http://internal.corp/resource', { headers: { 'Connection': 'keep-alive', 'Authorization': type1msg } }, function (err, res) { // Server responds with Type 2 challenge in www-authenticate header console.log(res.headers['www-authenticate']); }); ``` ``` -------------------------------- ### Compute LM Password Hash for NTLM Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Computes the LAN Manager (LM) hash of a plaintext password as a Buffer. This can be used for pre-computing credentials. ```javascript var httpntlm = require('httpntlm'); var ntlm = httpntlm.ntlm; var lmHash = ntlm.create_LM_hashed_password('P@ssw0rd'); // => (16 bytes) // Use the pre-computed hash instead of the plaintext password: httpntlm.get({ url: 'http://internal.corp/api/data', username: 'jdoe', lm_password: lmHash, nt_password: ntlm.create_NT_hashed_password('P@ssw0rd'), domain: 'CORP' }, function (err, res) { if (err) return console.error(err); console.log(res.body); }); ``` -------------------------------- ### ntlm.parseType2Message Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Decodes the server's Type 2 challenge from the `www-authenticate` response header. Returns a structured object containing the server challenge nonce, negotiate flags, target name, and optional target info. Calls `callback(err)` on parse failure. ```APIDOC ## ntlm.parseType2Message(rawHeader, callback) ### Description Decodes the server's Type 2 challenge from the `www-authenticate` response header. Returns a structured object containing the server challenge nonce, negotiate flags, target name, and optional target info (used for NTLMv2). Calls `callback(err)` on parse failure. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method ```javascript ntlm.parseType2Message(rawHeader, callback) ``` ### Parameters - **rawHeader** (string) - The raw `www-authenticate` header value from the server. - **callback** (function) - A callback function that will be called with an error argument if parsing fails. ### Response - **type** (number) - The NTLM message type (should be 2). - **serverChallenge** (Buffer) - The server's challenge nonce. - **negotiateFlags** (number) - The negotiate flags. - **targetName** (string) - The target name. - **targetInfo** (object | null) - Optional target information, used for NTLMv2. ### Request Example ```javascript var ntlm = require('httpntlm').ntlm; // Raw www-authenticate header value from the server: var rawHeader = 'NTLM TlRMTVNTUAACAAAAHgAeADgAAAAFgoqi...'; var type2msg = ntlm.parseType2Message(rawHeader, function (err) { console.error('Parse error:', err); }); if (type2msg) { console.log('Type:', type2msg.type); console.log('Challenge:', type2msg.serverChallenge); console.log('Flags:', type2msg.negotiateFlags); console.log('Has targetInfo:', !!type2msg.targetInfo); } ``` ``` -------------------------------- ### ntlm.create_LM_hashed_password Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Computes the LAN Manager (LM) hash of a plaintext password, returning it as a `Buffer`. This can be used for pre-computed credentials. ```APIDOC ## ntlm.create_LM_hashed_password(password) ### Description Generates the LM hash of a given password. This hash can be used directly in NTLM authentication requests, avoiding the need to pass plaintext passwords. ### Parameters - **password** (string) - Required - The plaintext password to hash. ### Returns - **Buffer** - The computed LM password hash (16 bytes). ### Usage Example ```javascript var httpntlm = require('httpntlm'); var ntlm = httpntlm.ntlm; var lmHash = ntlm.create_LM_hashed_password('P@ssw0rd'); // Use the pre-computed hash instead of the plaintext password: httpntlm.get({ url: 'http://internal.corp/api/data', username: 'jdoe', lm_password: lmHash, nt_password: ntlm.create_NT_hashed_password('P@ssw0rd'), domain: 'CORP' }, function (err, res) { if (err) return console.error(err); console.log(res.body); }); ``` ``` -------------------------------- ### Perform Authenticated HTTP POST Request with httpntlm Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Use this to send a POST request with a body to an NTLM-protected endpoint. Body data and content-type are passed through to the final request. ```javascript var httpntlm = require('httpntlm'); httpntlm.post({ url: 'http://internal.corp/api/items', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'New Item', value: 42 }) }, function (err, res) { if (err) return console.error(err); console.log('Status:', res.statusCode); console.log('Response:', res.body); // => Status: 201 }); ``` -------------------------------- ### Perform Authenticated HTTP PUT Request with httpntlm Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Use this to send a PUT request to an NTLM-protected endpoint. It supports custom headers and request bodies. ```javascript var httpntlm = require('httpntlm'); httpntlm.put({ url: 'http://internal.corp/api/items/1', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'Updated Item' }) }, function (err, res) { if (err) return console.error(err); console.log('Status:', res.statusCode); // => 200 }); ``` -------------------------------- ### Reuse Keep-Alive Agent for HTTP NTLM Requests Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Pass a custom `http.Agent` with `keepAlive: true` to reuse TCP connections across multiple NTLM-authenticated calls, improving performance. ```javascript var httpntlm = require('httpntlm'); var http = require('http'); var keepaliveAgent = new http.Agent({ keepAlive: true }); function makeRequest(done) { httpntlm.get({ url: 'http://internal.corp/api/data', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP', agent: keepaliveAgent // reused across calls }, done); } makeRequest(function (err, res1) { if (err) return console.error(err); console.log('First call status:', res1.statusCode); makeRequest(function (err, res2) { if (err) return console.error(err); console.log('Second call status:', res2.statusCode); // Same TCP connection is reused for the second call }); }); ``` -------------------------------- ### httpntlm.patch(options, callback) Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Performs an authenticated HTTP PATCH request to an NTLM-protected endpoint. Supports standard httpreq options and NTLM credentials. ```APIDOC ## httpntlm.patch(options, callback) ### Description Sends a PATCH request to an NTLM-protected endpoint. Supports standard httpreq options and NTLM credentials. ### Parameters #### Options Object - **url** (string) - Required - The URL to send the PATCH request to. - **username** (string) - Required - The username for NTLM authentication. - **password** (string) - Required - The password for NTLM authentication. - **domain** (string) - Optional - The domain name (default: ''). - **headers** (object) - Optional - Custom headers to send with the request. - **body** (string) - Optional - The data to send in the request body. ### Callback Function - **err** - An error object if the request failed, otherwise null. - **res** - The response object containing statusCode and body. ### Request Example ```js var httpntlm = require('httpntlm'); httpntlm.patch({ url: 'http://internal.corp/api/items/1', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ value: 99 }) }, function (err, res) { if (err) return console.error(err); console.log('Status:', res.statusCode); // => 200 }); ``` ``` -------------------------------- ### Reusing Keep-Alive Agent Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Improves performance by reusing a single TCP connection across multiple requests using a custom `http.Agent` with `keepAlive: true`. ```APIDOC ## httpntlm.get with Keep-Alive Agent ### Description Reuse a TCP connection for multiple NTLM-authenticated requests by providing a pre-configured `http.Agent` with `keepAlive: true`. ### Method `httpntlm.get(options, callback)` ### Parameters #### Options - **url** (string) - Required - The URL to request. - **username** (string) - Required - The username for NTLM authentication. - **password** (string) - Required - The password for NTLM authentication. - **domain** (string) - Required - The domain for NTLM authentication. - **agent** (http.Agent | https.Agent) - Optional - A custom agent instance, typically configured with `keepAlive: true`. ### Request Example ```javascript var httpntlm = require('httpntlm'); var http = require('http'); var keepaliveAgent = new http.Agent({ keepAlive: true }); function makeRequest(done) { httpntlm.get({ url: 'http://internal.corp/api/data', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP', agent: keepaliveAgent // reused across calls }, done); } makeRequest(function (err, res1) { if (err) return console.error(err); console.log('First call status:', res1.statusCode); makeRequest(function (err, res2) { if (err) return console.error(err); console.log('Second call status:', res2.statusCode); }); }); ``` ``` -------------------------------- ### Perform Authenticated HTTP PATCH Request with httpntlm Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Use this to send a PATCH request to an NTLM-protected endpoint. It supports custom headers and request bodies. ```javascript var httpntlm = require('httpntlm'); httpntlm.patch({ url: 'http://internal.corp/api/items/1', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ value: 99 }) }, function (err, res) { if (err) return console.error(err); console.log('Status:', res.statusCode); // => 200 }); ``` -------------------------------- ### ntlm.createType3Message Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Constructs the base64-encoded NTLM Type 3 authentication message. Automatically selects NTLMv2 when the server negotiated extended security and provided target info; otherwise falls back to NTLMv1. Accepts either a plaintext `password` or pre-computed `lm_password`/`nt_password` buffers. ```APIDOC ## ntlm.createType3Message(type2msg, options) ### Description Constructs the base64-encoded NTLM Type 3 authentication message. Automatically selects NTLMv2 when the server negotiated extended security and provided target info; otherwise falls back to NTLMv1. Accepts either a plaintext `password` or pre-computed `lm_password`/`nt_password` buffers. ### Method ```javascript ntlm.createType3Message(type2msg, options) ``` ### Parameters - **type2msg** (object) - The parsed Type 2 message object obtained from `ntlm.parseType2Message`. - **options** (object) - An object containing authentication details: - **username** (string) - The username for authentication. - **password** (string) - The plaintext password (if not using pre-computed hashes). - **lm_password** (Buffer) - Optional pre-computed LM password hash. - **nt_password** (Buffer) - Optional pre-computed NT password hash. - **domain** (string) - The domain name. - **workstation** (string) - The workstation name. ### Response - (string) - The base64-encoded NTLM Type 3 authentication message. ### Request Example ```javascript var ntlm = require('httpntlm').ntlm; var async = require('async'); var httpreq = require('httpreq'); var https = require('https'); var options = { url: 'https://internal.corp/api/secure', username: 'jdoe', password: 'P@ssw0rd', workstation: 'MYPC', domain: 'CORP' }; var keepaliveAgent = new https.Agent({ keepAlive: true }); async.waterfall([ // Step 1: Send Type 1 message function (callback) { var type1msg = ntlm.createType1Message(options); httpreq.get(options.url, { headers: { 'Connection': 'keep-alive', 'Authorization': type1msg }, agent: keepaliveAgent, allowRedirects: false }, callback); }, // Step 2: Parse Type 2 challenge and send Type 3 response function (res, callback) { if (!res.headers['www-authenticate']) return callback(new Error('No www-authenticate header')); var type2msg = ntlm.parseType2Message(res.headers['www-authenticate'], callback); if (!type2msg) return; var type3msg = ntlm.createType3Message(type2msg, options); setImmediate(function () { httpreq.get(options.url, { headers: { 'Connection': 'Close', 'Authorization': type3msg }, allowRedirects: false, agent: keepaliveAgent }, callback); }); } ], function (err, res) { if (err) return console.error('Auth failed:', err.message); console.log('Authenticated! Status:', res.statusCode); console.log('Body:', res.body); }); ``` ``` -------------------------------- ### httpntlm.delete(options, callback) Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Performs an authenticated HTTP DELETE request to an NTLM-protected endpoint. Supports standard httpreq options and NTLM credentials. ```APIDOC ## httpntlm.delete(options, callback) ### Description Sends a DELETE request to an NTLM-protected endpoint. Supports standard httpreq options and NTLM credentials. ### Parameters #### Options Object - **url** (string) - Required - The URL to send the DELETE request to. - **username** (string) - Required - The username for NTLM authentication. - **password** (string) - Required - The password for NTLM authentication. - **domain** (string) - Optional - The domain name (default: ''). ### Callback Function - **err** - An error object if the request failed, otherwise null. - **res** - The response object containing statusCode and body. ### Request Example ```js var httpntlm = require('httpntlm'); httpntlm.delete({ url: 'http://internal.corp/api/items/1', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP' }, function (err, res) { if (err) return console.error(err); console.log('Status:', res.statusCode); // => 204 }); ``` ``` -------------------------------- ### Perform Authenticated HTTP DELETE Request with httpntlm Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Use this to send a DELETE request to an NTLM-protected endpoint. No request body is typically sent with DELETE requests. ```javascript var httpntlm = require('httpntlm'); httpntlm.delete({ url: 'http://internal.corp/api/items/1', username: 'jdoe', password: 'P@ssw0rd', domain: 'CORP' }, function (err, res) { if (err) return console.error(err); console.log('Status:', res.statusCode); // => 204 }); ``` -------------------------------- ### Build NTLM Type 3 Message Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Constructs the base64-encoded NTLM Type 3 authentication message. Automatically selects NTLMv2 when the server negotiated extended security and provided target info; otherwise falls back to NTLMv1. Accepts either a plaintext password or pre-computed lm_password/nt_password buffers. ```javascript var ntlm = require('httpntlm').ntlm; var async = require('async'); var httpreq = require('httpreq'); var https = require('https'); var options = { url: 'https://internal.corp/api/secure', username: 'jdoe', password: 'P@ssw0rd', workstation: 'MYPC', domain: 'CORP' }; var keepaliveAgent = new https.Agent({ keepAlive: true }); async.waterfall([ // Step 1: Send Type 1 message function (callback) { var type1msg = ntlm.createType1Message(options); httpreq.get(options.url, { headers: { 'Connection': 'keep-alive', 'Authorization': type1msg }, agent: keepaliveAgent, allowRedirects: false }, callback); }, // Step 2: Parse Type 2 challenge and send Type 3 response function (res, callback) { if (!res.headers['www-authenticate']) return callback(new Error('No www-authenticate header')); var type2msg = ntlm.parseType2Message(res.headers['www-authenticate'], callback); if (!type2msg) return; var type3msg = ntlm.createType3Message(type2msg, options); setImmediate(function () { httpreq.get(options.url, { headers: { 'Connection': 'Close', 'Authorization': type3msg }, allowRedirects: false, agent: keepaliveAgent }, callback); }); } ], function (err, res) { if (err) return console.error('Auth failed:', err.message); console.log('Authenticated! Status:', res.statusCode); console.log('Body:', res.body); }); ``` -------------------------------- ### Parse NTLM Type 2 Message Source: https://context7.com/samdecrock/node-http-ntlm/llms.txt Decodes the server's Type 2 challenge from the www-authenticate response header. Returns a structured object containing server challenge nonce, negotiate flags, target name, and optional target info. Calls callback(err) on parse failure. ```javascript var ntlm = require('httpntlm').ntlm; // Raw www-authenticate header value from the server: var rawHeader = 'NTLM TlRMTVNTUAACAAAAHgAeADgAAAAFgoqi...'; var type2msg = ntlm.parseType2Message(rawHeader, function (err) { console.error('Parse error:', err); }); if (type2msg) { console.log('Type:', type2msg.type); // => 2 console.log('Challenge:', type2msg.serverChallenge); // => console.log('Flags:', type2msg.negotiateFlags); // => -1567981051 console.log('Has targetInfo:', !!type2msg.targetInfo); // => true (NTLMv2 capable) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.