代码之家  ›  专栏  ›  技术社区  ›  ds19

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

  •  1
  • ds19  · 技术社区  · 6 年前

    我正在开发一个TFS扩展,尝试访问仪表盘的RESTAPI。

    扩展几乎分配了所有作用域:

      "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 回复  |  直到 6 年前
        1
  •  1
  •   Cece Dong - MSFT    6 年前

    请检查一下你有没有 {team} 在baseuri中,这是必需的。其余的API应该如下所示:

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