作者:Liko2502860873 | 来源:互联网 | 2022-12-06 18:51
我正在尝试从Node.js编写的IBM Cloud Function访问botshop.cloudappsportal.com上托管的Sharepoint文件中的一些表数据.
我可以在站点上访问Sharepoint的REST API,但身份验证失败.我的理解是,Sharepoint使用了一些复杂的Microsoft身份验证.
这是Node.js代码,
const request = require('request-promise');
function main(params) {
var optiOns= {
uri: "http://xxx.botshop.cloudappsportal.com/_api/web/lists/getbytitle('myfile')/items",
method: 'GET',
auth: {
'user': 'myuser@botshop.cloudappsportal.com',
'pass': 'password'
}
}
return request.get(options).then(respOnse=> {
return response;
});
}
exports.main = main;
在提示输入用户名/密码后,我可以从浏览器访问该URL.
我也可以使用NTCredentials类从Java访问它.
HttpGet request = new HttpGet("http://xxx.botshop.cloudappsportal.com/_api/web/lists/getbytitle('myfile')/items");
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 1000);
HttpConnectionParams.setSoTimeout(httpParams, 1000);
DefaultHttpClient client = new DefaultHttpClient(httpParams);
client.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY),
new NTCredentials("myuser@botshop.cloudappsportal.com", "password", "", ""));
HttpResponse respOnse= client.execute(request);
普通的UsernamePasswordCredentials在Java中不起作用,因此我需要Node.js中的NTCredentials(在IBM Cloud Functions中有效).有任何想法吗?
同样奇怪的是,域的额外参数只是""""有效,奇怪的是当它不传递任何额外的有用数据时需要NTCredentials.