我创建了一个 GitHub 应用程序并将其安装在我的帐户中,使其能够访问我帐户中的私有存储库。 GitHub 应用程序具有元数据的读取权限。
然后,我按照此处的步骤生成了 JWT 并使用它来创建安装访问令牌。
我尝试使用此令牌使用 GitHub 搜索 API 在上述私有存储库中搜索关键字,如下所示:
https://api.github.com/search/code?q=abc+in:file+repo:username/private-repo
但是,这会返回以下响应。
{
"message": "Validation Failed",
"errors": [
{
"message": "The listed users and repositories cannot be searched either because the resources do not exist or you do not have permission to view them.",
"resource": "Search",
"field": "q",
"code": "invalid"
}
],
"documentation_url": "https://docs.github.com/v3/search/"
}
我尝试使用此访问令牌来获取此 GitHub 应用程序安装的存储库,并在响应中成功返回私有存储库。我认为这意味着安装可以访问私人存储库并且令牌按预期工作。
使用的API:https://api.github.com/installation/repositories
.
那么为什么搜索会失败呢?
向 GitHub 支持提出了请求。他们的回应:
查询失败,因为GitHub App没有权限read
私有存储库的内容。元数据read
权限将允许您搜索存储库,但没有
足够的范围read
存储库的内容(私有)。
The docs https://docs.github.com/en/rest/reference/permissions-required-for-github-apps在元数据下列出搜索 API,但它应该在内容权限下。授予内容read
GitHub 应用程序的权限解决了该问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)