Categorygithub.com/int128/oauth2-github-app
modulepackage
1.1.1
Repository: https://github.com/int128/oauth2-github-app.git
Documentation: pkg.go.dev

# README

oauth2-github-app go Go Reference

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.

  1. Create a GitHub App
  2. Download a private key of the GitHub App
  3. 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.

# Packages

No description provided by the author

# Functions

LoadPrivateKey reads the private key file of GitHub App.
ParsePrivateKey parses the private key of GitHub App.

# Structs

Config represents a config of GitHub App Installation.