GitHub 应用程序身份验证问题:无法刷新安装 ID 令牌

问题描述 投票:0回答:2

我在使用 GitHub 应用程序针对 Github 进行正确身份验证时遇到问题。

我正在使用这个例子:

https://github.com/swinton/example-golang-github-app/blob/main/go-probot/probot.go

我只需更改以下代码:

https://github.com/swinton/example-golang-github-app/blob/99e6061c5da3ec7b191d389b45e262acf4d4632f/go-probot/app.go#L58

使用下一个(对我来说任何一个都不起作用);因为我不使用自己的安装:

client := github.NewClient(&http.Client{Transport: itr})

它显示的错误是:

could not refresh installation id 140xxxx28's token: request received non 2xx response status

我正在使用 ghinstallation 作为 google/go-github 库的推荐。

我认为我已正确设置所有内容。如果我不与 API 交互,我会正确接收 Webhook。当我调用 API 时,我收到了上一条消息。

set GITHUB_BASE_URL=https://api.github.com/
set GITHUB_APP_ID=9xxx4
set GITHUB_APP_PRIVATE_KEY_PATH=x-01-11.private-key.pem
set GITHUB_APP_WEBHOOK_SECRET=gaxxxxias

enter image description here

有什么想法吗?

非常感谢你


编辑:完整的错误跟踪

time="2021-01-11T20:59:41+01:00" level=info msg="Post \"https://api.github.com/repos/xxxxxxx/example-app/pulls/552756737/comments\": could not refresh installation id 140xx928's token: request &{Method:POST URL:https://api.github.com/app/installations/140xx928/access_tokens Proto:HTTP/1.1 ProtoM
ajor:1 ProtoMinor:1 Header:map[Accept:[application/vnd.github.machine-man-preview+json application/vnd.github.machine-man-preview+json] Authorization:[Bearer eyJhbGciOiJSUzIxxxxxXXXXxxxxxxxS5doAR1fAd-h2qh6IXhiIjmdgBKZhJRWgRu2TBZOrpVPuCxTRxEGoQUqRKRVDyfSWgHqEVCo3GWvZUG0ClWqGHr6adl2Ca0g] Content-Type:[appl
ication/json]] Body:{Reader:} GetBody:0x6bcbe0 ContentLength:5 TransferEncoding:[] Close:false Host:api.github.com Form:map[] PostForm:map[] MultipartForm:<nil> Trailer:map[] RemoteAddr: RequestURI: TLS:<nil> Cancel:<nil> Response:<nil> ctx:0xc00000c0a0} received non 2xx response status &{%!q(*http.body=&{0xc00
0384060 <nil> <nil> false false {0 0} false false false <nil>}) {'\\x00' '\\x00'} %!q(bool=false) <nil> %!q(func(error) error=0x6be580) %!q(func() error=0x6be500)} with body &{Method:POST URL:https://api.github.com/app/installations/140xx928/access_tokens Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Acce
pt:[application/vnd.github.machine-man-preview+json application/vnd.github.machine-man-preview+json] Authorization:[Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTAzOTUyNDEsImlhdCI6MTYxMDM5NTE4MSwiaXNzIjoiOTU4MDQifQ.UUistaOIXBImexxxxxxxxxxxj2eLTHsK24gpJ86pk053FXM3NniStaYIDmzF9CbxBZN4gb0FufnTxKO1rF3WKLiDeLD372__8RCyuxmFHTFQ-D56OpjxPgI5nl83kSvnAS5doAR1fAd-h2qh6IXhiIjmdgBKZhJRWgRu2TBZOrpVPuCxTRxEGoQUqRKRVDyfSWgHqEVCo3GWvZUG0ClWqGHr6adl2Ca0g] Content-Type:[application/json]] Body:{Reader:} GetBo
dy:0x6bcbe0 ContentLength:5 TransferEncoding:[] Close:false Host:api.github.com Form:map[] PostForm:map[] MultipartForm:<nil> Trailer:map[] RemoteAddr: RequestURI: TLS:<nil> Cancel:<nil> Response:<nil> ctx:0xc00000c0a0} and TLS &{Version:772 HandshakeComplete:true DidResume:false CipherSuite:4865 NegotiatedProt
ocol:http/1.1 NegotiatedProtocolIsMutual:true ServerName:api.github.com PeerCertificates:[0xc00000ac00 0xc00000b180] VerifiedChains:[[0xc00000b700 0xc00025a000 0xc00025a580]] SignedCertificateTimestamps:[] OCSPResponse:[] TLSUnique:[] ekm:0x62f720}"
go github github-api
2个回答
0
投票

解决方案或至少问题的原因在这里:

界定问题后,我找到了根源,即计算机配置问题(安全化)。在另一台装有 Linux 的计算机上,甚至在另一台没有这些限制的 Windows 计算机上,它可以正常工作,并且可以毫无问题地刷新令牌。

所以问题既不在实现的代码中,也不在机器人配置中,也不在 Ngrok 中。


0
投票

该问题已由其作者回答,但我仍保留此答案,因为它可能对其他人有帮助。

我收到了同样的错误消息。原来我使用了错误的 github 应用程序的私钥。我还注意到,如果我使用不正确的密钥(故意删除部分密钥),我会收到相同的错误消息。

© www.soinside.com 2019 - 2024. All rights reserved.