Documentation
¶
Overview ¶
Package auth provides GitHub authentication utilities.
Index ¶
- Constants
- func GetAuthenticatedUser(ctx context.Context, gh *github.Client) (string, error)
- func GetUser(ctx context.Context, gh *github.Client, username string) (*github.User, error)
- func NewAppClient(ctx context.Context, cfg *AppConfig) (*github.Client, error)
- func NewGitHubClient(ctx context.Context, token string) *github.Client
- func NewTokenClient(ctx context.Context, token string) *http.Client
- type AppConfig
- type AppInstallation
- type AuthError
Constants ¶
const ( // UsernameDependabot is the username for GitHub's Dependabot. UsernameDependabot = "dependabot[bot]" // UserIDDependabot is the user ID for GitHub's Dependabot. UserIDDependabot = 49699333 )
Known bot users.
Variables ¶
This section is empty.
Functions ¶
func GetAuthenticatedUser ¶
GetAuthenticatedUser returns the authenticated user's login.
func NewAppClient ¶ added in v0.11.0
NewAppClient creates a GitHub client authenticated as a GitHub App installation. The client uses an installation access token that is valid for 1 hour.
func NewGitHubClient ¶
NewGitHubClient creates a GitHub client authenticated with the given token.
Types ¶
type AppConfig ¶ added in v0.11.0
type AppConfig struct {
AppID int64 `json:"app_id"`
InstallationID int64 `json:"installation_id"`
PrivateKeyPath string `json:"private_key_path"`
PrivateKey []byte `json:"-"` // Can be set directly instead of via path
}
AppConfig holds GitHub App configuration.
func LoadAppConfig ¶ added in v0.11.0
LoadAppConfig loads GitHub App configuration from environment variables or config file. Environment variables take precedence over config file values.
Environment variables:
- GITHUB_APP_ID: The GitHub App ID
- GITHUB_INSTALLATION_ID: The installation ID for the target org/repo
- GITHUB_PRIVATE_KEY_PATH: Path to the private key PEM file
- GITHUB_PRIVATE_KEY: The private key PEM content (alternative to path)
Config file location (in order of precedence):
- $XDG_CONFIG_HOME/gogithub/app.json
- ~/.config/gogithub/app.json
func LoadAppConfigFromFile ¶ added in v0.11.0
LoadAppConfigFromFile loads GitHub App configuration from a specific file path.
type AppInstallation ¶ added in v0.11.0
AppInstallation contains information about a GitHub App installation.
func ListAppInstallations ¶ added in v0.11.0
func ListAppInstallations(ctx context.Context, cfg *AppConfig) ([]AppInstallation, error)
ListAppInstallations lists all installations of the GitHub App. This requires authenticating as the App (using JWT), not as an installation.