google / google/go-github

Add first party support for Github App

Open
#3,005 6 comments 10 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
11.3k
Forks
2.5k
Avg merge
1d 22h
Merged PRs (30d)
49

Description

Many of the apis requires to be invoked as Github App, eg. https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28. And currently we need to use third-party packages like [ghinstallation](https://github.com/bradleyfalzon/ghinstallation) to do so.

However, this is not the full story. When creating a Github App, it involves many different kinds of creds:

- [as Github App itself](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app)
- [as Github App installation](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation)
- [as Github App user](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-with-a-github-app-on-behalf-of-a-user)

And we need to use different cred to call different APIs. For now, the only way to do so is to create many different `github.Client`s, each holding a different credential.

And we need to do this with extra care, as all these token are short-lived, and need to be cached/refreshed periodically. Which means, blindly creating those clients will cause lots of rate limiting issues.

For instance, to use `github.ChecksService`, we need:

- Auth as Github App itself by creating a JWT with app's private key, to call `github.AppServiceCreateInstallationToken`
- Once we have the token, we can auth as app installation, then calling `github.ChecksService`

Which requires 2 `github.Client`s in total.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.