vsts扩展程序Git Rest Client未经授权

时间:2019-03-29 08:15:55

标签: git tfs azure-devops pull-request

我尝试创建一个Azure DevOps扩展,以获取当前的请求请求。但我面临未经授权的例外:
enter image description here

我检查了请求中发送的令牌,这与我得到的相同:

VSS.getAccessToken().then(function(token) {
    var authHeader = VSS_Auth_Service.authTokenManager.getAuthorizationHeader(token);
    console.log(authHeader);
});

git客户端是这样实例化的:

VSS.require(["VSS/Service", "TFS/VersionControl/GitRestClient"], function (VSS_Service, TFS_Wit_WebApi) {
    // Get the REST client
    var gitClient = VSS_Service.getCollectionClient(TFS_Wit_WebApi.GitHttpClient2_2);

    gitClient.getPullRequest(tabContext.repositoryId, tabContext.pullRequestId)
             .thenResolve(pr => {
                console.log(pr);
             });
    });

我也这样尝试过:


VSS.require(["VSS/Service", "TFS/VersionControl/GitRestClient"], function (VSS_Service, TFS_Wit_WebApi) {
    // Get the REST client
    var gitClient = TFS_Wit_WebApi.getClient();

    gitClient.getPullRequest(tabContext.repositoryId, tabContext.pullRequestId)
             .thenResolve(pr => {
                console.log(pr);
             });
    });

扩展清单是:


{
    "manifestVersion": 1,
    "id": "complete-pr-extension",
    "publisher": "aguafrommars",
    "version": "1.0.8",
    "name": "Complete Pull Request",
    "description": "Complete a Pull Request with commity zen",
    "public": false,
    "categories": ["Code"],
    "targets": [
        {
            "id": "Microsoft.VisualStudio.Services"
        }
    ],
    "contributions": [
        {
            "id": "pull-request-details-tab",
            "type": "ms.vss-web.tab",
            "targets": [
                "ms.vss-code-web.pr-tabs"
            ],
            "properties": {
                "name": "Complete Pull Request",
                "title": "Complete Pull Request",
                "uri": "complete-pr.html",
                "action": "PR Details Tab"
            }
        }
    ],
    "files": [
        {
            "path": "complete-pr.html",
            "addressable": true
        },
        {
            "path": "node_modules/vss-web-extension-sdk/lib",
            "addressable": true,
            "packagePath": "lib"
        }
    ]
}

然后使用以下命令将扩展安装到本地TFS 2018 Update 2:

tfx extension publish --service-url http://localhost:8080/tfs --token {my-token} --rev-version

1 个答案:

答案 0 :(得分:1)

我发现我的问题在哪里,我错过了在清单中添加范围:

[

您可以在Extension manifest reference documentation

中找到所有可用范围