【发布时间】:2019-03-01 21:02:38
【问题描述】:
使用 express 和 express-ntlm,我如何创建一个 http://localhost:3000/api/bug/ 端点,通过点击 TFS api 在 TFS 中为我创建一个错误?
我现在可以使用request-ntlm-promise 执行此操作,我就是这样做的。
const ntlm = require('request-ntlm-promise');
const ntlmOptions = {
username: 'myUserName',
password: 'myPassword',
url: 'http://tfsinstance/collection/project/_apis/wit/workitems/$bug?api-version=4.1',
headers: {
'Content-Type': 'application/json-patch+json'
}
};
const tfsBugObject =[{
'op': 'add',
'path': '/fields/System.Title',
'value': 'Test title'
}, {
'op': 'add',
'path': '/fields/Microsoft.VSTS.TCM.SystemInfo',
'value': 'Test system info'
}, {
'op': 'add',
'path': '/fields/Microsoft.VSTS.TCM.ReproSteps',
'value': 'test reproduction steps'
}];
ntlm.post(ntlmOptions, tfsBugObject).then((response) => { return res.send(response); });
问题是我必须在ntlmOptions 对象中提供用户名和密码。这样做不会在当前用户点击 express API 时在 TFS 中创建错误,而是作为用户“myUserName”创建错误。
使用 express-ntlm 包,是否可以使用从该包返回的 NTLM 凭据执行 http.post 到 http://tfsinstance/collection/project/...?
TFS 需要身份验证才能使用 API。
使用express-ntlm 我希望我能做到以下几点。
const express = require('express');
const ntlm = require('express-ntlm');
const http = require('http');
const app = express();
app.use(ntlm({ domain: 'mydomain', domaincontroller: 'ldap://domaincontroller' });
然后
httpOptions = {
protocol: 'http',
hostname: 'tfsinstance',
pathname: '/collection/project/_apis/wit/workitems/$bug?api-version=4.1',
port: 8080,
method: 'POST',
headers: {
'Content-Type': 'application/json-patch+json'
}
};
app.post('/report/bug', (req, res, next) => {
const request = http.request(httpOptions, (response => {
response.on('data', data => {
// return response from TFS through express to user
});
}));
});
【问题讨论】:
标签: express tfs ntlm express-ntlm