...
1# ghinstallation
2
3[](https://godoc.org/github.com/bradleyfalzon/ghinstallation)
4
5`ghinstallation` provides `Transport`, which implements `http.RoundTripper` to
6provide authentication as an installation for GitHub Apps.
7
8This library is designed to provide automatic authentication for
9https://github.com/google/go-github or your own HTTP client.
10
11See
12https://developer.github.com/apps/building-integrations/setting-up-and-registering-github-apps/about-authentication-options-for-github-apps/
13
14# Installation
15
16Get the package:
17
18```bash
19GO111MODULE=on go get -u github.com/bradleyfalzon/ghinstallation/v2
20```
21
22# GitHub Example
23
24```go
25import "github.com/bradleyfalzon/ghinstallation/v2"
26
27func main() {
28 // Shared transport to reuse TCP connections.
29 tr := http.DefaultTransport
30
31 // Wrap the shared transport for use with the app ID 1 authenticating with installation ID 99.
32 itr, err := ghinstallation.NewKeyFromFile(tr, 1, 99, "2016-10-19.private-key.pem")
33 if err != nil {
34 log.Fatal(err)
35 }
36
37 // Use installation transport with github.com/google/go-github
38 client := github.NewClient(&http.Client{Transport: itr})
39}
40```
41
42# GitHub Enterprise Example
43
44For clients using GitHub Enterprise, set the base URL as follows:
45
46```go
47import "github.com/bradleyfalzon/ghinstallation/v2"
48
49const GitHubEnterpriseURL = "https://github.example.com/api/v3"
50
51func main() {
52 // Shared transport to reuse TCP connections.
53 tr := http.DefaultTransport
54
55 // Wrap the shared transport for use with the app ID 1 authenticating with installation ID 99.
56 itr, err := ghinstallation.NewKeyFromFile(tr, 1, 99, "2016-10-19.private-key.pem")
57 if err != nil {
58 log.Fatal(err)
59 }
60 itr.BaseURL = GitHubEnterpriseURL
61
62 // Use installation transport with github.com/google/go-github
63 client := github.NewEnterpriseClient(GitHubEnterpriseURL, GitHubEnterpriseURL, &http.Client{Transport: itr})
64}
65```
66
67## What is app ID and installation ID
68
69`app ID` is the GitHub App ID. \
70You can check as following : \
71Settings > Developer > settings > GitHub App > About item
72
73`installation ID` is a part of WebHook request. \
74You can get the number to check the request. \
75Settings > Developer > settings > GitHub Apps > Advanced > Payload in Request
76tab
77
78```
79WebHook request
80...
81 "installation": {
82 "id": `installation ID`
83 }
84```
85
86# License
87
88[Apache 2.0](LICENSE)
89
90# Dependencies
91
92- [github.com/golang-jwt/jwt-go](https://github.com/golang-jwt/jwt-go)
View as plain text