TFS扩展-TF400813:用户...无权访问此资源

时间:2018-07-05 16:15:35

标签: azure-devops tfs2018 azure-devops-rest-api

我正在开发一个TFS扩展,试图访问仪表板Rest API。

该扩展程序几乎分配了所有范围:

  "scopes": [
    "vso.build_execute",
    "vso.code_write",
    "vso.code_manage",
    "vso.dashboards_manage",
    "vso.dashboards",
    "vso.extension_manage",
    "vso.extension.data_write",
    "vso.gallery_manage",
    "vso.identity",
    "vso.notification_manage",
    "vso.packaging_manage",
    "vso.profile",
    "vso.project",
    "vso.project_manage",
    "vso.release_manage"
  ],

以下代码正在调用API:

var webContext = VSS.getWebContext();
console.log(`Collection URI: ${webContext.collection.uri}`);
console.log(`Project Name: ${webContext.project.name}`);
console.log(`User uniquename: ${webContext.user.uniqueName} id: ${webContext.user.id}`);
var baseUri = webContext.collection.uri + "/" + webContext.project.name;
var endpointUri = baseUri + "/_apis/dashboard/dashboards";
console.log(endpointUri);
var authToken = vssAuthentificationService.authTokenManager.getAuthorizationHeader(token);
console.log(authToken);
$.ajax({
    type: "GET",
    url: endpointUri,
    contentType: 'application/json',
    dataType: 'json',
    headers: { 'Authorization': authToken }
})
    .done(function (data) {
        console.log(data);
    });

返回:

401 (Unauthorized); TF400813: The user ... is not authorized to access this resource  

如果我将API uri更改为:

var endpointUri = baseUri + "/_apis/build/builds";  

响应正常。

使用该扩展名的用户是TFS集合管理员。

我需要设置哪种权限/范围才能访问仪表板API?

TFS版本16.131.27701.1

1 个答案:

答案 0 :(得分:1)

请检查您的baseUri中是否有{team},这是必需的。其余的api应该如下所示:

GET https://{accountName}.visualstudio.com/{project}/{team}/_apis/dashboard/dashboards?api-version=4.1-preview.2