Rod*_*nez 11 api curl oauth github jenkins
我有一个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的一些基本原理用谷歌搜索了一段时间,我还没有找到任何东西
mjs*_*ltz 14
我不确定你是否已经深究这一点,但在尝试了几条路线后,我终于在Jenkins上使用Github OAuth进行了脚本化构建.诀窍是API令牌不是 GitHub的一个,而是Jenkins的一个.
对于我的设置,我在github上有一个机器用户,我通过网络正常登录该用户,然后点击右上角的用户名.从那里我点击了左侧菜单上的"配置",最后在主要内容区域中点击了"显示API令牌".
有一次,我可以运行:
curl --user <username>:<api_token> https://jenkins-server/user/<username>/api/json/?pretty=true
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6346 次 |
最近记录: |