确定给定Github令牌的授权范围

Ton*_*ada 6 github github-api

我的应用程序使用Github的Oauth.假设:

  • 在版本1中,应用程序只需要基本授权(scopes = [])
  • 在版本2中,应用程序需要R/W访问公共存储库(scope = ['public_repo'])

自升级以来,有些用户尚未登录.

现在我有一些令牌具有更强的授权能力,而其他令牌.我如何区分它们?换句话说,我怎么能问Github:"嘿,我有这个oauth令牌......我能用它做什么?"

小智 12

您可以发出任何GitHub API请求并读取X-OAuth-Scopes标头的值,以查看令牌提供的范围.使用/ rate_limit不会计入您应用的速率限制.

curl -I -H 'Authorization: token <token>' https://api.github.com/rate_limit
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 18 Oct 2012 23:48:37 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Status: 200 OK
Content-Length: 61
X-GitHub-Media-Type: github.beta
X-RateLimit-Remaining: 4999
X-RateLimit-Limit: 5000
X-OAuth-Scopes: public_repo
Cache-Control: 
X-Content-Type-Options: nosniff
Run Code Online (Sandbox Code Playgroud)