TFS REST API授权获取,但没有补丁



我正在尝试使用我的TFS 2015 Update 3(前提)提供的REST API更改工作项的状态。当我尝试获取物品列表时,一切正常:

var client = new RestClient(uri);
client.Authenticator = new HttpBasicAuthenticator(this.TFSUsername, this.SecurityToken);
var request = new RestRequest(Method.GET);
request.AddHeader("cache-control", "no-cache");
IRestResponse response = client.Execute(request);

得到这个答案后,我拥有所需的所有信息,我将更新这些工作项目之一的状态。

使用相同的方法(当然,相同的凭据),我正在获取401状态代码,我试图匿名进行

唯一的区别是我正在使用动词补丁(如文档所说的那样),并且我正在通过一个身体来确定我要编辑的状态。

这是我用于编辑的代码:

var client = new RestClient(uri);
client.Authenticator = new HttpBasicAuthenticator(this.TFSUsername, this.SecurityToken);
var request = new RestRequest(Method.PATCH);
request.AddHeader("cache-control", "no-cache");
string body = @"
  {
   'op':'add',
   'path':'/fields/System.State',
   'value':'Closed'
  }";
request.AddJsonBody(body);
IRestResponse response = client.Execute(request);

为什么要更改HTTP动词引起我这个授权问题的任何提示?

试图与Postman一起做这件事也使我同样的问题。

更新:

看响应标头,我注意到了这一点:

X-TFS-ProcessId →e2b98235-1d3a-4bb7-868f-0d91805aa307
ActivityId →08909688-ac81-4c37-9cea-b47e84fd3efe
X-TFS-Session →08909688-ac81-4c37-9cea-b47e84fd3efe
X-VSS-E2EID →08909688-ac81-4c37-9cea-b47e84fd3efe
X-FRAME-OPTIONS →SAMEORIGIN
WWW-Authenticate →Basic realm="http://xxxxxxx/tfs"
WWW-Authenticate →Negotiate
WWW-Authenticate →NTLM
X-Powered-By →ASP.NET
P3P →CP="CAO DSP COR ADMa DEV CONo TELo CUR PSA PSD TAI IVDo OUR SAMi BUS DEM NAV STA UNI COM INT PHY ONL FIN PUR LOC CNT"
Lfs-Authenticate →NTLM
X-Content-Type-Options →nosniff
Date →Thu, 28 Feb 2019 00:20:57 GMT
Content-Length →0

引起我注意的是:

www-authenticate→基本境界=" http://xxxxxxx/tfs"

www-authenticate→谈判

www-authenticate→ntlm

因此,它将支持基本身份验证,但行不通。"谈判"one_answers" ntlm"是否以某种方式干扰?

谢谢

经过很多尝试后,我发现解决方案非常容易。

从身份验证的角度使其起作用,使用 ntlMauthenticator (带有用户名和密码)而不是HTTPBASICATENTENTICATICTICATOR(即使为GET工作)就足够了。我用ntlmauthenticator替换了authenticator的get和patch,现在正常工作。

var client = new RestClient(uri);
client.Authenticator = new NtlmAuthenticator(this.TFSUsername, this.TFSPassword);

我发现的另一个棘手的部分(与身份验证相关的不确定链接)是,对于补丁,内容类型必须为 application/json-patch json json

希望它有帮助

最新更新