【问题标题】:Use express-ntlm authentication to auth to TFS api使用 express-ntlm 身份验证对 TFS api 进行身份验证
【发布时间】:2019-03-01 21:02:38
【问题描述】:

使用 expressexpress-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.posthttp://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


    【解决方案1】:

    express-ntlm 充当客户端和域控制器之间的代理。所以域控制器将与客户端处理身份验证,express-ntlm 只是充当中间人,直到身份验证成功。

    如果您可以使用某种 API 用户并使用 express-ntlm 来获取正确的用户名并将其传递给 TFS API,这将是最简单的方法,否则我建议您在两者之间创建自己的代理您的客户端和 TFS API。

    【讨论】:

      猜你喜欢
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多