小编Rod*_*nez的帖子

你如何使用CURL访问使用Github OAuth的jenkins api

我有一个jenkins服务器使用Github OAuth插件并在github的"授权应用程序"部分授权,它可以在我的浏览器中正常工作,只要我使用github进行身份验证,我就可以访问jenkins服务器.

有没有办法使用CURL或ruby客户端的oauth凭证/令牌访问jenkins服务器api?

我已经在https://github.com/settings/applications - >个人访问令牌 - >生成新令牌中生成了令牌(没有选项将其范围扩展到第三方应用程序)

该令牌可以正常访问github:

curl -H "Authorization: token cfbcff42e6a8a52a1076dd9fcxxxxxxxxxxxxxxx" https://api.github.com/user

但是,该令牌对jenkins-server无效:

curl -H "Authorization: token cfbcff42e6a8a52a1076dd9fcxxxxxxxxxxxxxxx" https://jenkins-server/user/restebanez/api/json/\?pretty\=true

它会生成此错误:

<html><head><meta http-equiv='refresh' content='1;url=/securityRealm/commenceLogin?from=%2Fuser%2Frestebanez%2Fapi%2Fjson%2F%3Fpretty%3Dtrue'/><script>window.location.replace('/securityRealm/commenceLogin?from=%2Fuser%2Frestebanez%2Fapi%2Fjson%2F%3Fpretty%3Dtrue');</script></head><body style='background-color:white; color:white;'>


    Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:

                        Permission you need to have (but didn't): hudson.model.Hudson.Read
 ... which is implied by: hudson.security.Permission.GenericRead
 ... which is implied by: hudson.model.Hudson.Administer
-->

</body></html>     
Run Code Online (Sandbox Code Playgroud)

```

jenkins服务器安装了GitHub API Plugin 1.58和Github Authentication插件0.19

我可能错过了oauth b/ci的一些基本原理用谷歌搜索了一段时间,我还没有找到任何东西

api curl oauth github jenkins

11
推荐指数
1
解决办法
6346
查看次数

标签 统计

api ×1

curl ×1

github ×1

jenkins ×1

oauth ×1