Kerberos authentication in Node.js https.get or https.request

后端 未结 5 1690
失恋的感觉
失恋的感觉 2020-12-05 15:13

I\'m trying to write a simple script that requests some data from a tool on an internal network. Here is the code:

#!/usr/bin/node

var https = require(\'htt         


        
5条回答
  •  眼角桃花
    2020-12-05 15:40

    2020 UPD:

    The newer version of kerberos npm package has much less methods. But I make it work:

    const kerberos = require('kerberos').Kerberos;
    const fetch = require('node-fetch');
    
    (async () => {
        const client = await kerberos.initializeClient("HTTP@site.internal.net", {
            mechOID: kerberos.GSS_MECH_OID_SPNEGO,
        })
    
        const ticket = await client.step("")
    
        const resp = await fetch("https://site.internal.net/api/v1/hello", {
            headers: {
                'Authorization': 'Negotiate ' + ticket
            }
        })
    
        console.log(await resp.json())
    })();
    

    Works perfectly at Windows and Linux, should work at macOS too.

提交回复
热议问题