首页 文章

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

提问于
浏览
1

我正在开发一个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 回答

  • 1

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

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

相关问题