auth

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 12 Imported by: 5

Documentation

Overview

Package auth provides GitHub authentication utilities.

Index

Constants

View Source
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

func GetAuthenticatedUser(ctx context.Context, gh *github.Client) (string, error)

GetAuthenticatedUser returns the authenticated user's login.

func GetUser

func GetUser(ctx context.Context, gh *github.Client, username string) (*github.User, error)

GetUser returns information about a specific user.

func NewAppClient added in v0.11.0

func NewAppClient(ctx context.Context, cfg *AppConfig) (*github.Client, error)

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

func NewGitHubClient(ctx context.Context, token string) *github.Client

NewGitHubClient creates a GitHub client authenticated with the given token.

func NewTokenClient

func NewTokenClient(ctx context.Context, token string) *http.Client

NewTokenClient creates an HTTP 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

func LoadAppConfig() (*AppConfig, error)

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

func LoadAppConfigFromFile(path string) (*AppConfig, error)

LoadAppConfigFromFile loads GitHub App configuration from a specific file path.

type AppInstallation added in v0.11.0

type AppInstallation struct {
	ID      int64
	Account string
	Type    string // "User" or "Organization"
}

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.

type AuthError

type AuthError struct {
	Message string
	Err     error // Wrapped error for Go 1.13+ error chain compatibility
}

AuthError indicates an authentication failure.

func (*AuthError) Error

func (e *AuthError) Error() string

func (*AuthError) Unwrap added in v0.4.0

func (e *AuthError) Unwrap() error

Unwrap returns the wrapped error for Go 1.13+ error chain compatibility.

Jump to

Keyboard shortcuts

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