@node-ntlm/core
v0.3.2
Published
NTLM node utility function
Downloads
676
Maintainers
Readme
@node-ntlm/core
@node-ntlm/core is a Node.js NTLM utility package
It's heavily inspired from httpntlm written in typescript and with nodejs 18 support.
Install
You can install @node-ntlm/core using the Node Package Manager (npm):
npm install @node-ntlm/core
How to use
import {
createType1Message,
createType3Message,
extractNtlmMessageFromAuthenticateHeader,
parseType2Message,
} from '@node-ntlm/core';
import { fetch } from 'undici';
const negotiateMessage = createType1Message({ domain: 'test.host', workstation: 'pc1' });
const negotiateResponse = await fetch('http://test-service.url/api', {
headers: { authorization: negotiateMessage },
keepalive: true,
});
const type2Message = extractNtlmMessageFromAuthenticateHeader(negotiateResponse.headers.get('www-authenticate'));
if (!type2Message) {
throw new Error('Could not find type 2 message on response headers!');
}
const authMessage = createType3Message(parseType2Message(type2Message), {
domain: 'test.host',
workstation: 'pc1',
username: 'test',
password: 'test',
});
const result = await fetch('http://test-service.url/api', {
headers: { Authorization: authMessage },
keepalive: false,
});
console.log(await result.json());
@node-ntlm/core/testing
Usage:
import { generateNegotiateResponse } from '@node-ntlm/core/testing';
const negotiateRespnse = generateNegotiateResponse(...getAuthorization header somewhere)