【问题标题】:Check scopes of GitHub token检查 GitHub 令牌的范围
【发布时间】:2022-01-07 00:16:55
【问题描述】:

我想被动地检查 GitHub 安全令牌的权限(范围)(而不是将某些内容推送到存储库中)。我尝试了以下命令。我替换了 your_username: 你的访问令牌和我的仓库的 URL。但它显示一个错误。

curl:(3) URL 使用错误/非法格式或缺少 URL

curl -u your_username:your_access_token \
 -H "Accept: application/vnd.github.v3+json" \
 https://api.github.com/repos/octocat/hello-world/collaborators/USERNAME/permission

【问题讨论】:

标签: rest github access-token github-api


【解决方案1】:

如果目标是确定令牌可以访问哪些范围,请检查带有前缀 x-oauth-scopes 的响应标头(使用 curl-I):

$ GITHUB_TOKEN=ghp_DefineYourOwnToken
$ curl -sS -f -I -H "Authorization: token ${GITHUB_TOKEN}" https://api.github.com | grep ^x-oauth-scopes: | cut -d' ' -f2- | tr -d "[:space:]" | tr ',' '\n'

请注意,上面的 tr -d "[:space:]" 对于删除一些不寻常的空格至关重要,否则,grep -x 等匹配命令随后将无法正常工作。

示例输出 1:

gist
repo
workflow

示例输出 2:

delete:packages
public_repo
read:packages
repo:invite
repo:status

信用:answer by VK

【讨论】:

  • 这对我不起作用我的 github 操作中的令牌没有返回结果,所以没有权限......
猜你喜欢
  • 2021-08-26
  • 2020-11-16
  • 2019-05-15
  • 1970-01-01
  • 2021-01-02
  • 1970-01-01
  • 1970-01-01
  • 2020-09-16
  • 1970-01-01
相关资源
最近更新 更多