使用 OAuth 和 PyGithub 请求私有仓库访问

时间:2021-06-18 19:05:10

标签: oauth scope private public pygithub

在使用 PyGithub 库在 OAuth 中授权用户时,我无法找到请求“repo”范围的方法。

我的团队正在构建一个“代码库分析器”网站,该网站可提供有关所选代码库中代码的见解。我们正在使用 Git API 的 PyGithub 实现。我们正在使用 OAuth 来授权用户,它非常适用于公共存储库。但是,我无法成功指定范围。我尝试了下面的“Github.oauth_scopes”,这显然是错误的。非常感谢任何提示!

在截图中可以看到 OAuth 只是请求公共数据,我们也需要提示访问私有存储库,这意味着使用“repo”范围:GitApiScopeDoc

from github import *

g = Github()

#request repo scope
Github.oauth_scopes = "repo"

#authorization using oauth
clientID = "enterclientidhere"
secret = "entersecrethere"
oauth = g.get_oauth_application(clientID, secret)
url = oauth.get_login_url()

#print the url, then we follow the url to github which requests a users identity
print(url)

screenshot

0 个答案:

没有答案