Documentation
¶
Overview ¶
Package githubauth provides utilities for GitHub authentication, including generating and using GitHub App tokens and installation tokens. The package is based on the go-github and golang.org/x/oauth2 libraries. It implements a set of TokenSource interfaces for generating GitHub App and installation tokens.
Index ¶
- Constants
- func NewApplicationTokenSource(id int64, privateKey []byte, opts ...ApplicationTokenOpt) (oauth2.TokenSource, error)
- func NewInstallationTokenSource(id int64, src oauth2.TokenSource, opts ...InstallationTokenSourceOpt) oauth2.TokenSource
- type ApplicationTokenOpt
- type InstallationTokenSourceOpt
- func WithContext(ctx context.Context) InstallationTokenSourceOpt
- func WithEnterpriseURLs(baseURL, uploadURL string) InstallationTokenSourceOpt
- func WithHTTPClient(client *http.Client) InstallationTokenSourceOpt
- func WithInstallationTokenOptions(opts *github.InstallationTokenOptions) InstallationTokenSourceOpt
Constants ¶
const ( // DefaultApplicationTokenExpiration is the default expiration time for the GitHub App token. // The expiration time of the JWT, after which it can't be used to request an installation token. // The time must be no more than 10 minutes into the future. DefaultApplicationTokenExpiration = 10 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
func NewApplicationTokenSource ¶
func NewApplicationTokenSource(id int64, privateKey []byte, opts ...ApplicationTokenOpt) (oauth2.TokenSource, error)
NewApplicationTokenSource creates a new GitHub App token source using the provided application ID and private key. Functional options can be passed to customize the token source.
func NewInstallationTokenSource ¶
func NewInstallationTokenSource(id int64, src oauth2.TokenSource, opts ...InstallationTokenSourceOpt) oauth2.TokenSource
NewInstallationTokenSource creates a new GitHub App installation token source using the provided installation ID and token source. Functional options can be passed to customize the installation token source.
Types ¶
type ApplicationTokenOpt ¶
type ApplicationTokenOpt func(*applicationTokenSource)
ApplicationTokenOpt is a functional option for ApplicationTokenSource.
func WithApplicationTokenExpiration ¶
func WithApplicationTokenExpiration(expiration time.Duration) ApplicationTokenOpt
WithApplicationTokenExpiration sets the expiration for the GitHub App token. The expiration time of the JWT must be no more than 10 minutes into the future and greater than 0. If the provided expiration is invalid, the default expiration is used.
type InstallationTokenSourceOpt ¶
type InstallationTokenSourceOpt func(*installationTokenSource)
InstallationTokenSourceOpt is a functional option for InstallationTokenSource.
func WithContext ¶ added in v1.1.0
func WithContext(ctx context.Context) InstallationTokenSourceOpt
WithContext sets the context for the GitHub App installation token source.
func WithEnterpriseURLs ¶ added in v1.1.0
func WithEnterpriseURLs(baseURL, uploadURL string) InstallationTokenSourceOpt
WithEnterpriseURLs sets the base URL and upload URL for the GitHub App installation token source. This should passed after WithHTTPClient to ensure the HTTP client is updated with the new URLs. If the provided URLs are invalid, the default GitHub URLs are used.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) InstallationTokenSourceOpt
WithHTTPClient sets the HTTP client for the GitHub App installation token source.
func WithInstallationTokenOptions ¶
func WithInstallationTokenOptions(opts *github.InstallationTokenOptions) InstallationTokenSourceOpt
WithInstallationTokenOptions sets the options for the GitHub App installation token.