Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

bradleyfalzon/ghinstallation

Repository files navigation

Go Reference

ghinstallation providesTransport, which implementshttp.RoundTripper toprovide authentication as an installation for GitHub Apps.

This library is designed to provide automatic authentication forhttps://github.com/google/go-github or your own HTTP client.

Seehttps://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/about-authentication-with-a-github-app

Installation

Get the package:

go get -u github.com/bradleyfalzon/ghinstallation/v2

GitHub Example

import"github.com/bradleyfalzon/ghinstallation/v2"funcmain() {// 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")iferr!=nil {log.Fatal(err)}// Use installation transport with github.com/google/go-githubclient:=github.NewClient(&http.Client{Transport:itr})}

You can also useNew() 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"constGitHubEnterpriseURL="https://github.example.com/api/v3"funcmain() {// 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")iferr!=nil {log.Fatal(err)}itr.BaseURL=GitHubEnterpriseURL// Use installation transport with github.com/google/go-githubclient:=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 Requesttab

WebHook request...  "installation": {    "id": `installation ID`  }

Customizing signing behavior

Users can customize signing behavior by passing in aSignerimplementation when creating anAppsTransport.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

Apache 2.0

Dependencies

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors28

Languages


[8]ページ先頭

©2009-2025 Movatter.jp