Windows Integrated Authentication in node.js Client

后端 未结 3 521
情歌与酒
情歌与酒 2020-11-28 04:16

When using node.js as a client, is it possible to connect to a server using Windows integrated authentication (e.g. when connecting to IIS)?

My searches for this onl

3条回答
  •  佛祖请我去吃肉
    2020-11-28 05:05

    For client side, what works is to use node-libcurl to do REST / HTTP calls.

    here's sample code:

    var endpoint = urlString;
    var url = require("url");
    var endpointUrl = url.parse(endpoint);
    
    var Curl = require( 'node-libcurl' ).Curl;
    var curl = new Curl();
    
    curl.setOpt( 'USERNAME', '' );
    //curl.setOpt( 'VERBOSE', 1 );
    curl.setOpt( 'URL', endpoint );
    curl.setOpt( 'HTTPAUTH', Curl.auth.NEGOTIATE );
    curl.setOpt( 'NOPROXY', endpointUrl.hostname );
    
    curl.on( 'end', function( statusCode, body, headers ) {
    
        if (statusCode === 200) {
            console.log(body);
            cb(null, { statusCode, body, headers } ); 
        } else {
            cb(new Error(), { statusCode, body, headers } ); 
        }
    
        this.close();
    });
    
    curl.on( 'error', curl.close.bind( curl ) );
    curl.perform();
    

提交回复
热议问题