Using express
and express-ntlm
, how can I create an http://localhost:3000/api/bug/
endpoint that creates a bug for me in TFS by hitting the TFS api?
I can do this using request-ntlm-promise
right now and this is how I do it.
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); });
The problem is that I must provide a username and password in in ntlmOptions
object. Doing this doesn't create the bug in TFS as the current user hitting the express API but instead creates the bug as the user 'myUserName'.
Using the express-ntlm
package, is it possible to do an http.post
to http://tfsinstance/collection/project/...
using the NTLM credentials returned from that package?
TFS requires authentication in order for one to use the API.
Using express-ntlm
I was hoping that I could do the following.
const express = require('express');
const ntlm = require('express-ntlm');
const http = require('http');
const app = express();
app.use(ntlm({ domain: 'mydomain', domaincontroller: 'ldap://domaincontroller' });
then
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-ntlm
acts as a proxy between a client and a domain controller. So the domain controller will handle the authentication with the client andexpress-ntlm
just acts as a man in the middle until the authentication was successful.If you can use some kind of API user and use
express-ntlm
to just get the correct username and pass it to the TFS API that would be the easiest way to do, otherwise I would suggest you to create your own proxy between your client and the TFS API.