ghinstallation

HTTP Round Tripper for GitHub Apps - Authenticate as an Installation Workflow

Github星跟蹤圖

ghinstallation

GoDoc

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.

See
https://developer.github.com/apps/building-integrations/setting-up-and-registering-github-apps/about-authentication-options-for-github-apps/

Installation

Get the package:

go get -u github.com/bradleyfalzon/ghinstallation

GitHub Example

import "github.com/bradleyfalzon/ghinstallation"

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})
}

GitHub Enterprise Example

For clients using GitHub Enterprise, set the base URL as follows:

import "github.com/bradleyfalzon/ghinstallation"

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`
  }

License

Apache 2.0

Dependencies

主要指標

概覽
名稱與所有者bradleyfalzon/ghinstallation
主編程語言Go
編程語言Go (語言數: 1)
平台
許可證Apache License 2.0
所有者活动
創建於2016-10-26 11:24:09
推送於2025-05-30 19:37:26
最后一次提交2025-05-05 16:23:40
發布數28
最新版本名稱v2.16.0 (發布於 )
第一版名稱v0.1.0 (發布於 )
用户参与
星數339
關注者數8
派生數100
提交數163
已啟用問題?
問題數36
打開的問題數9
拉請求數93
打開的拉請求數5
關閉的拉請求數24
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?