bradleyfalzon/ghinstallation
关于
用于 GitHub Apps 的 HTTP Round Tripper——以安装实例身份进行身份验证的工作流
开发工具实测星标增长
- 24小时
- 0
- 7天
- +1
- 15天
- +2
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文ghinstallation
ghinstallation provides Transport, which implements http.RoundTripper to
provide authentication as an installation for GitHub Apps.
This library is designed to provide automatic authentication for https://github.com/google/go-github or your own HTTP client.
Installation
Get the package:
go get -u github.com/bradleyfalzon/ghinstallation/v2
GitHub Example
import "github.com/bradleyfalzon/ghinstallation/v2"
func main() {
// Shared transport to reuse TCP connections.
tr := http.DefaultTransport
// Wrap the shared transport for use with the app ID 1 authenticating with installation ID 99.
itr, err := ghinstallation.NewKeyFromFile(tr, 1, 99, "2016-10-19.private-key.pem")
if err != nil {
log.Fatal(err)
}
// Use installation transport with github.com/google/go-github
client := github.NewClient(&http.Client{Transport: itr})
}
You can also use New() to load a key directly from a []byte.
GitHub Enterprise Example
For clients using GitHub Enterprise, set the base URL as follows:
import "github.com/bradleyfalzon/ghinstallation/v2"
const GitHubEnterpriseURL = "https://github.example.com/api/v3"
func main() {
// Shared transport to reuse TCP connections.
tr := http.DefaultTransport
// Wrap the shared transport for use with the app ID 1 authenticating with installation ID 99.
itr, err := ghinstallation.NewKeyFromFile(tr, 1, 99, "2016-10-19.private-key.pem")
if err != nil {
log.Fatal(err)
}
itr.BaseURL = GitHubEnterpriseURL
// Use installation transport with github.com/google/go-github
client := github.NewEnterpriseClient(GitHubEnterpriseURL, GitHubEnterpriseURL, &http.Client{Transport: itr})
}
What is app ID and installation ID
app ID is the GitHub App ID.
You can check as following :
Settings > Developer > settings > GitHub App > About item
installation ID is a part of WebHook request.
You can get the number to check the request.
Settings > Developer > settings > GitHub Apps > Advanced > Payload in Request
tab
WebHook request
...
"installation": {
"id": `installation ID`
}
Customizing signing behavior
Users can customize signing behavior by passing in a Signer implementation when creating an AppsTransport. For example, this can be used to create tokens backed by keys in a KMS system.
signer := &myCustomSigner{
key: "https://url/to/key/vault",
}
atr := NewAppsTransportWithOptions(http.DefaultTransport, 1, WithSigner(signer))
tr := NewFromAppsTransport(atr, 99)
License
Dependencies
探索相关项目
加载中…