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

auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatAPIStatusError added in v0.0.8

func FormatAPIStatusError(statusCode int, body []byte) error

FormatAPIStatusError builds an error for a non-success GitHub API response, adding actionable context for failure modes whose raw message is misleading.

Types

type Authenticator

type Authenticator struct {
	// contains filtered or unexported fields
}

Authenticator handles GitHub App authentication.

func NewAuthenticator

func NewAuthenticator() *Authenticator

NewAuthenticator creates a new authenticator.

func (*Authenticator) GenerateJWT

func (a *Authenticator) GenerateJWT(issuer any, privateKeyPath string) (string, error)

GenerateJWT generates a JWT token for the GitHub App (legacy file-based method). The issuer may be the numeric App ID (int64) or the Client ID (string).

func (*Authenticator) GenerateJWTForApp

func (a *Authenticator) GenerateJWTForApp(app *config.GitHubApp) (string, error)

GenerateJWTForApp generates a JWT token using the app's configured private key source.

func (*Authenticator) GetCredentials

func (a *Authenticator) GetCredentials(app *config.GitHubApp, repoURL string) (token, username string, err error)

GetCredentials returns username and token for git credential helper.

Example

Example showing the authentication flow

// This example shows the expected flow for GetCredentials
// Real implementation requires GitHub API mock server

fmt.Println("Authentication flow:")
fmt.Println("1. Check cache for existing token")
fmt.Println("2. If not cached, generate JWT")
fmt.Println("3. Exchange JWT for installation token")
fmt.Println("4. Cache the installation token")
fmt.Println("5. Return token and username")
Output:
Authentication flow:
1. Check cache for existing token
2. If not cached, generate JWT
3. Exchange JWT for installation token
4. Cache the installation token
5. Return token and username

func (*Authenticator) GetInstallationToken

func (a *Authenticator) GetInstallationToken(jwtToken string, installationID int64, repoURL string) (string, error)

GetInstallationToken exchanges JWT for an installation access token.

func (*Authenticator) MintInstallationToken added in v0.1.0

func (a *Authenticator) MintInstallationToken(app *config.GitHubApp, repoURL string) (string, error)

MintInstallationToken generates and returns a fresh installation token without using the cache.

Jump to

Keyboard shortcuts

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