Movatterモバイル変換


[0]ホーム

URL:


Alert GO-2022-1178: JWT leak in github.com/bradleyfalzon/ghinstallation
Notice  The highest tagged major version isv2.

ghinstallation

packagemodule
v1.1.1Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2020 License:Apache-2.0Imports:13Imported by:161

Details

Repository

github.com/bradleyfalzon/ghinstallation

Links

README

ghinstallation

GoDoc

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://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 Requesttab

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

License

Apache 2.0

Dependencies

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcGetReadWriteradded inv0.1.3

func GetReadWriter(i interface{}) (io.ReadWriter,error)

GetReadWriter converts a body interface into an io.ReadWriter object.

Types

typeAppsTransportadded inv0.1.2

type AppsTransport struct {BaseURLstring// BaseURL is the scheme and host for GitHub API, defaults tohttps://api.github.comClientClient// Client to use to refresh tokens, defaults to http.Client with provided transport// contains filtered or unexported fields}

AppsTransport provides a http.RoundTripper by wrapping an existinghttp.RoundTripper and provides GitHub Apps authentication as aGitHub App.

Client can also be overwritten, and is useful to change to one whichprovides retry logic if you do experience retryable errors.

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

funcNewAppsTransportadded inv0.1.2

func NewAppsTransport(trhttp.RoundTripper, appIDint64, privateKey []byte) (*AppsTransport,error)

NewAppsTransport returns a AppsTransport using private key. The key is parsedand if any errors occur the error is non-nil.

The provided tr http.RoundTripper should be shared between multipleinstallations to ensure reuse of underlying TCP connections.

The returned Transport's RoundTrip method is safe to be used concurrently.

funcNewAppsTransportFromPrivateKeyadded inv1.1.0

func NewAppsTransportFromPrivateKey(trhttp.RoundTripper, appIDint64, key *rsa.PrivateKey) *AppsTransport

NewAppsTransportFromPrivateKey returns an AppsTransport using a crypto/rsa.(*PrivateKey).

funcNewAppsTransportKeyFromFileadded inv0.1.2

func NewAppsTransportKeyFromFile(trhttp.RoundTripper, appIDint64, privateKeyFilestring) (*AppsTransport,error)

NewAppsTransportKeyFromFile returns a AppsTransport using a private key from file.

func (*AppsTransport)RoundTripadded inv0.1.2

func (t *AppsTransport) RoundTrip(req *http.Request) (*http.Response,error)

RoundTrip implements http.RoundTripper interface.

typeClient

type Client interface {Do(*http.Request) (*http.Response,error)}

Client is a HTTP client which sends a http.Request and returns a http.Responseor an error.

typeTransport

type Transport struct {BaseURLstring// BaseURL is the scheme and host for GitHub API, defaults tohttps://api.github.comClientClient// Client to use to refresh tokens, defaults to http.Client with provided transportInstallationTokenOptions *github.InstallationTokenOptions// parameters restrict a token's access// contains filtered or unexported fields}

Transport provides a http.RoundTripper by wrapping an existinghttp.RoundTripper and provides GitHub Apps authentication as aninstallation.

Client can also be overwritten, and is useful to change to one whichprovides retry logic if you do experience retryable errors.

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

funcNew

func New(trhttp.RoundTripper, appID, installationIDint64, privateKey []byte) (*Transport,error)

New returns an Transport using private key. The key is parsedand if any errors occur the error is non-nil.

The provided tr http.RoundTripper should be shared between multipleinstallations to ensure reuse of underlying TCP connections.

The returned Transport's RoundTrip method is safe to be used concurrently.

funcNewFromAppsTransportadded inv1.1.0

func NewFromAppsTransport(atr *AppsTransport, installationIDint64) *Transport

NewFromAppsTransport returns a Transport using an existing *AppsTransport.

funcNewKeyFromFile

func NewKeyFromFile(trhttp.RoundTripper, appID, installationIDint64, privateKeyFilestring) (*Transport,error)

NewKeyFromFile returns a Transport using a private key from file.

func (*Transport)Permissionsadded inv0.1.3

func (t *Transport) Permissions() (github.InstallationPermissions,error)

Permissions returns a transport token's GitHub installation permissions.

func (*Transport)Repositoriesadded inv0.1.3

func (t *Transport) Repositories() ([]github.Repository,error)

Repositories returns a transport token's GitHub repositories.

func (*Transport)RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response,error)

RoundTrip implements http.RoundTripper interface.

func (*Transport)Token

func (t *Transport) Token(ctxcontext.Context) (string,error)

Token checks the active token expiration and renews if necessary. Token returnsa valid access token. If renewal fails an error is returned.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp