Help us shape the future of Go! Take the 2026 Go Developer Survey

githubapp

package
v0.73.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 14 Imported by: 1

Documentation

Overview

Package githubapp 提供 GitHub App 凭证能力:用 App 的 RSA 私钥签发 RS256 JWT(第一层凭证),以及用该 JWT 换取 installation access token(第二层 凭证,实际调 GitHub API 用)。独立成包是为了让 git-sync-core、git-ferry 等下游共享同一实现,删掉各自手写的重复代码。

Index

Constants

View Source
const DefaultAPIBase = "https://api.github.com"

DefaultAPIBase 是 GitHub 公有 API 地址;GitHub Enterprise Server 传各自 的域名(如 https://ghe.example.com/api/v3)。

Variables

This section is empty.

Functions

func FetchInstallationToken

func FetchInstallationToken(ctx context.Context, apiBase string, appID, installationID int64, privateKeyPEM string) (string, error)

FetchInstallationToken 用 JWT 换 installation access token(有效期约 1h)。 apiBase 为空时取 DefaultAPIBase,尾部斜杠会被去掉。

请求走 transport.Client 而不是裸 http.Client,以复用平台统一的重试/日志/ 钩子链路;access_tokens 是不幂等的写操作,默认重试配置只允许"请求根本 没发出去"(DNS/dial 失败)级别的安全重试,不会重放已到达服务端的 POST。

func MintJWT

func MintJWT(appID int64, privateKeyPEM string) (string, error)

MintJWT 用 App 私钥签发 RS256 JWT,iss=app_id,iat=now-30(容忍调用方与 GitHub 之间的时钟偏移),exp=now+9 分钟(GitHub 限制 JWT 有效期 ≤10 分钟, 留 1 分钟余量)。支持 PKCS#1 与 PKCS#8 两种 PEM RSA 私钥格式——GitHub App 下载的 .pem 是 PKCS#8,openssl genrsa 产出的是 PKCS#1,两者都常见。

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL