【问题标题】:nodejs app - download file from sharepoint with NTLM AUTHnodejs 应用程序-使用 NTLM AUTH 从共享点下载文件
【发布时间】:2014-07-18 18:42:49
【问题描述】:

我必须承认我被困住了。我需要一个 nodejs 应用程序来从 SharePoint 库下载文件。很简单吧?不,不是简单的 OOTB SharePoint。唯一允许的 SSL,添加了特定的强制标头,当然只有基于域的 NTLM 身份验证方法。

我已经尝试过似乎可以提前工作的 httpntlm (https://www.npmjs.org/package/httpntlm),但没有。 SP 响应出现错误消息。

我尝试过 node-sharepoint,但它还不支持 NTLM。应用获得 ETIMEDOUT 响应。

任何想法,欢迎。

【问题讨论】:

  • 任何幸运的人我都处于同样的情况

标签: node.js sharepoint ssl download ntlm


【解决方案1】:

我可以使用 httpntlm 模块下载文件。您需要更改几行代码。将瀑布逻辑替换为 httpntlm.js 中的以下代码。

async.waterfall([
        function ($){
            var type1msg = ntlm.createType1Message(options);

            httpreq.get(options.url, {
                headers:{
                    'Connection' : 'keep-alive',
                    'Authorization': type1msg
                },
                agent: keepaliveAgent
            }, $);
        },

        function (res, $){
            if(!res.headers['www-authenticate'])
                return $(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);
            if(method!=='download'){
                httpreq[method](options.url, {
                    headers:{
                        'Connection' : 'Close',
                        'Authorization': type3msg
                    },
                    allowRedirects: false,
                    agent: keepaliveAgent
                }, $);
            }else{

                    //By Dheeraj for file download
                    httpreq.download(
                        url,
                    {
                        headers:{
                            'Connection' : 'Close',
                            'Authorization': type3msg
                        },
                        //allowRedirects: false,
                        agent: keepaliveAgent
                    },
                    __dirname + 'your_filename',                        
                     function (err, progress){
                        if (err) return console.log(err);
                        console.log(progress);
                    }, function (err, res){
                        if (err) return console.log(err);
                        console.log(res);
                    });

            }
        }
    ], callback);
};

['get', 'put', 'post', 'delete', 'head','download'].forEach(function(method){
  exports[method] = exports.method.bind(exports, method);
});

并替换 httpreq.js 的下载方法(httpntm_module/node_modules/httpreq_module/httpreq.js) 你可以在大约第 79 行找到它。

exports.download = function (url,options, downloadlocation, progressCallback, callback) {
    //var options = {};
    options.url = url;
    options.method = 'GET';
    options.downloadlocation = downloadlocation;
    options.allowRedirects = true;
    // if only 3 args are provided, so no progressCallback
    if(callback === undefined && progressCallback && typeof(progressCallback)==="function")
        callback = progressCallback;
    else
        options.progressCallback = progressCallback;

    doRequest(options, callback);
}

如果您仍然遇到问题,请告诉我。

【讨论】:

  • @port:你能分享你的电子邮件ID吗?所以我可以发送这个 httpntlm 模块。
  • 嗨。您是否能够使用此解决方案对 sharepoint 进行身份验证并从 sharepoint 获取数据?你也可以分享一下httpnlm模块吗?
猜你喜欢
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-09
  • 1970-01-01
  • 1970-01-01
  • 2020-07-30
  • 2014-09-15
相关资源
最近更新 更多