oauth2-github-app

This is a Go package for authenticating with a GitHub App Installation.
It is interoperable with golang.org/x/oauth2 package.
Getting Started
Prerequisite
Set up your GitHub App Installation.
- Create a GitHub App
- Download a private key of the GitHub App
- Install your GitHub App on your repository or organization
This package requires the following inputs:
- Private Key file
- App ID (number)
- Installation ID (number)
Create a client
To create an OAuth2 client with GitHub App installation token,
func run(ctx context.Context, appID, installationID, privateKeyFilename string) error {
privateKey, err := oauth2githubapp.LoadPrivateKey(privateKeyFilename)
if err != nil {
return fmt.Errorf("could not load the private key: %w", err)
}
// create a client
cfg := oauth2githubapp.Config{
PrivateKey: privateKey,
AppID: appID,
InstallationID: installationID,
}
client := oauth2.NewClient(ctx, cfg.TokenSource(ctx))
}For github.com/google/go-github package,
cfg := oauth2githubapp.Config{
PrivateKey: privateKey,
AppID: appID,
InstallationID: installationID,
}
client := github.NewClient(oauth2.NewClient(ctx, cfg.TokenSource(ctx)))For github.com/shurcooL/githubv4 package,
cfg := oauth2githubapp.Config{
PrivateKey: privateKey,
AppID: appID,
InstallationID: installationID,
}
client := githubv4.NewClient(oauth2.NewClient(ctx, cfg.TokenSource(ctx)))See also example.
GitHub Enterprise
To set your GitHub Enterprise server,
cfg := oauth2githubapp.Config{
PrivateKey: privateKey,
AppID: appID,
InstallationID: installationID,
BaseURL: "https://api.github.example.com",
}
client := oauth2.NewClient(ctx, cfg.TokenSource(ctx))Contribution
This is an open source software. Feel free to contribute to it.