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

TFS Extension - TF400813: The user ... is not authorized to access this resource

我正在开发一个 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);
    });

哪个returns:

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

如果我将 API uri 更改为:

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

响应正常。

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

我需要设置哪种 permissions/scopes 才能访问仪表板 API?

TFS 版本 16.131.27701.1

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

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