On Windows here. This answer seems to be correct, just might need couple of adjustments.
const client = await kerberos.initializeClient("HTTP/site.internal.net@DOMAIN.HERE", {
mechOID: kerberos.GSS_MECH_OID_SPNEGO,
})
Works both with GSS_MECH_OID_KRB5 and GSS_MECH_OID_SPNEGO.
Use klist from command line and you'll get an overview of existing kerberos tickets, their sites (e.g. site.internal.net) and domains (e.g. DOMAIN.HERE).
And kerberos flow is that you first get 401 with WWW-Authenticate: Negotiate header. Then you're supposed to issue second request to the url that responded with 401 (can be same url, can be redirect url) with 'Authorization': 'Negotiate ' + ticket as shown in example. Don't forget to reuse any Cookies from first request to maintain session.
Complete request might look something like this:
const kerberos = require('kerberos').Kerberos;
const fetch = require('node-fetch');
(async () => {
const client = await kerberos.initializeClient("HTTP/site.internal.net@DOMAIN.HERE", {
mechOID: kerberos.GSS_MECH_OID_SPNEGO, // or GSS_MECH_OID_KRB5
})
const ticket = await client.step("")
// 401 here, get cookies
const resp1 = await fetch("https://site.internal.net/api/v1/hello")
// ... code to handle cookies ...
const resp2 = await fetch("https://site.internal.net/api/v1/hello", {
headers: {
'Authorization': 'Negotiate ' + ticket,
'Cookie': // ... add cookies from first request ..
}
})
console.log(await resp2.json())
})();