项目作者: int128

项目描述 :
Go package for authenticating with GitHub App Installation
高级语言: Go
项目地址: git://github.com/int128/oauth2-github-app.git
创建时间: 2021-02-11T12:24:26Z
项目社区:https://github.com/int128/oauth2-github-app

开源协议:Apache License 2.0

下载


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,

  1. func run(ctx context.Context, appID, installationID, privateKeyFilename string) error {
  2. privateKey, err := oauth2githubapp.LoadPrivateKey(privateKeyFilename)
  3. if err != nil {
  4. return fmt.Errorf("could not load the private key: %w", err)
  5. }
  6. // create a client
  7. cfg := oauth2githubapp.Config{
  8. PrivateKey: privateKey,
  9. AppID: appID,
  10. InstallationID: installationID,
  11. }
  12. client := oauth2.NewClient(ctx, cfg.TokenSource(ctx))
  13. }

For github.com/google/go-github package,

  1. cfg := oauth2githubapp.Config{
  2. PrivateKey: privateKey,
  3. AppID: appID,
  4. InstallationID: installationID,
  5. }
  6. client := github.NewClient(oauth2.NewClient(ctx, cfg.TokenSource(ctx)))

For github.com/shurcooL/githubv4 package,

  1. cfg := oauth2githubapp.Config{
  2. PrivateKey: privateKey,
  3. AppID: appID,
  4. InstallationID: installationID,
  5. }
  6. client := githubv4.NewClient(oauth2.NewClient(ctx, cfg.TokenSource(ctx)))

See also example.

GitHub Enterprise

To set your GitHub Enterprise server,

  1. cfg := oauth2githubapp.Config{
  2. PrivateKey: privateKey,
  3. AppID: appID,
  4. InstallationID: installationID,
  5. BaseURL: "https://api.github.example.com",
  6. }
  7. client := oauth2.NewClient(ctx, cfg.TokenSource(ctx))

Contribution

This is an open source software. Feel free to contribute to it.