Documentation
¶
Overview ¶
Package githubauth provides interfaces and implementations for authenticating to GitHub.
Index ¶
- type App
- func (a *App) AppID() string
- func (g *App) AppToken() (string, error)
- func (a *App) InstallationForID(ctx context.Context, installationID string) (*AppInstallation, error)
- func (a *App) InstallationForOrg(ctx context.Context, org string) (*AppInstallation, error)
- func (a *App) InstallationForRepo(ctx context.Context, org, repo string) (*AppInstallation, error)
- func (a *App) InstallationForUser(ctx context.Context, user string) (*AppInstallation, error)
- func (a *App) OAuthAppTokenSource() oauth2.TokenSource
- type AppInstallation
- func (i *AppInstallation) AccessToken(ctx context.Context, request *TokenRequest) (string, error)
- func (i *AppInstallation) AccessTokenAllRepos(ctx context.Context, request *TokenRequestAllRepos) (string, error)
- func (i *AppInstallation) AllReposTokenSource(permissions map[string]string) TokenSource
- func (i *AppInstallation) App() *App
- func (i *AppInstallation) SelectedReposTokenSource(permissions map[string]string, repos ...string) TokenSource
- type Option
- type StaticTokenSource
- type TokenRequest
- type TokenRequestAllRepos
- type TokenSource
- type TokenSourceFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is an object that can be used to generate application level JWTs or to request an OIDC token on behalf of an installation.
func NewApp ¶
func NewApp[T *rsa.PrivateKey | string | []byte](appID string, privateKeyT T, opts ...Option) (*App, error)
NewApp creates a new GitHub App from the given inputs.
The privateKey can be the *rsa.PrivateKey, or a PEM-encoded string (or []byte) of the private key material.
func (*App) AppToken ¶
AppToken creates a signed JWT to authenticate a GitHub app so that it can make API calls to GitHub.
func (*App) InstallationForID ¶ added in v1.1.0
func (a *App) InstallationForID(ctx context.Context, installationID string) (*AppInstallation, error)
InstallationForID returns an AccessTokensURLFunc that gets the access token url for the given installation.
func (*App) InstallationForOrg ¶ added in v1.1.0
InstallationForOrg returns an AccessTokensURLFunc that gets the access token url for the given org context.
func (*App) InstallationForRepo ¶ added in v1.1.0
InstallationForRepo returns an AccessTokensURLFunc that gets the access token url for the given repo context.
func (*App) InstallationForUser ¶ added in v1.1.0
InstallationForUser returns an AccessTokensURLFunc that gets the access token url for the given user context.
func (*App) OAuthAppTokenSource ¶
func (a *App) OAuthAppTokenSource() oauth2.TokenSource
OAuthAppTokenSource adheres to the oauth2 TokenSource interface and returns a oauth2 token by creating a JWT token.
type AppInstallation ¶ added in v1.1.0
type AppInstallation struct {
// contains filtered or unexported fields
}
AppInstallation represents a specific installation of the app (on a repo, org, or user).
func (*AppInstallation) AccessToken ¶ added in v1.1.0
func (i *AppInstallation) AccessToken(ctx context.Context, request *TokenRequest) (string, error)
AccessToken calls the GitHub API to generate a new access token for this application installation with the requested permissions and repositories.
func (*AppInstallation) AccessTokenAllRepos ¶ added in v1.1.0
func (i *AppInstallation) AccessTokenAllRepos(ctx context.Context, request *TokenRequestAllRepos) (string, error)
AccessTokenAllRepos calls the GitHub API to generate a new access token for this application installation with the requested permissions and all granted repositories.
func (*AppInstallation) AllReposTokenSource ¶ added in v1.1.0
func (i *AppInstallation) AllReposTokenSource(permissions map[string]string) TokenSource
AllReposTokenSource returns a TokenSource that mints a GitHub token with permissions on all repos.
func (*AppInstallation) App ¶ added in v1.1.0
func (i *AppInstallation) App() *App
App returns the underlying app for this installation. This is a pointer back to the exact App that created the installation, meaning callers cannot assume exclusive ownership over the result.
func (*AppInstallation) SelectedReposTokenSource ¶ added in v1.1.0
func (i *AppInstallation) SelectedReposTokenSource(permissions map[string]string, repos ...string) TokenSource
SelectedReposTokenSource returns a TokenSource that mints a GitHub token with permissions on the selected repos.
type Option ¶
Option is a function that provides an option to the GitHub App creation.
func WithBaseURL ¶ added in v1.1.0
WithBaseURL allows overriding of the GitHub API url. This is usually only overidden for testing or private GitHub installations.
func WithHTTPClient ¶
WithHTTPClient is an option that allows a consumer to provider their own http client implementation. This HTTP client will be shared among all AppInstallation.
type StaticTokenSource ¶
type StaticTokenSource struct {
// contains filtered or unexported fields
}
StaticTokenSource is a GitHubToken provider that returns the provided token.
func NewStaticTokenSource ¶
func NewStaticTokenSource(token string) (*StaticTokenSource, error)
NewStaticTokenSource returns a StaticTokenSource which returns the token string as given.
func (*StaticTokenSource) GitHubToken ¶
func (s *StaticTokenSource) GitHubToken(ctx context.Context) (string, error)
GitHubToken implements TokenSource.
type TokenRequest ¶
type TokenRequest struct {
Repositories []string `json:"repositories"`
Permissions map[string]string `json:"permissions"`
}
TokenRequest is a struct that contains the list of repositories and the requested permissions / scopes that are requested when generating a new installation access token.
type TokenRequestAllRepos ¶
TokenRequestAllRepos is a struct that contains the requested permissions/scopes that are requested when generating a new installation access token.
This struct intentionally omits the repository properties to generate a token for all repositories granted to this GitHub app installation.
type TokenSource ¶
type TokenSource interface {
// GitHubToken returns a GitHub token, or any error that occurs.
GitHubToken(ctx context.Context) (string, error)
}
TokenSource is an interface which returns a GitHub token.
type TokenSourceFunc ¶
TokenSourceFunc is a function that implements TokenSource.
func (TokenSourceFunc) GitHubToken ¶
func (f TokenSourceFunc) GitHubToken(ctx context.Context) (string, error)