githubauth

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: Apache-2.0 Imports: 16 Imported by: 7

Documentation

Overview

Package githubauth provides interfaces and implementations for authenticating to GitHub.

Index

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) AppID

func (a *App) AppID() string

AppID returns the GitHub App's ID.

func (*App) AppToken

func (g *App) AppToken() (string, error)

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.

The initial invocation will make an API call to GitHub to get the access token URL for the installation; future calls will return the cached installation.

func (*App) InstallationForOrg added in v1.1.0

func (a *App) InstallationForOrg(ctx context.Context, org string) (*AppInstallation, error)

InstallationForOrg returns an AccessTokensURLFunc that gets the access token url for the given org context.

The initial invocation will make an API call to GitHub to get the access token URL for the installation; future calls will return the cached installation.

func (*App) InstallationForRepo added in v1.1.0

func (a *App) InstallationForRepo(ctx context.Context, org, repo string) (*AppInstallation, error)

InstallationForRepo returns an AccessTokensURLFunc that gets the access token url for the given repo context.

The initial invocation will make an API call to GitHub to get the access token URL for the installation; future calls will return the cached installation.

func (*App) InstallationForUser added in v1.1.0

func (a *App) InstallationForUser(ctx context.Context, user string) (*AppInstallation, error)

InstallationForUser returns an AccessTokensURLFunc that gets the access token url for the given user context.

The initial invocation will make an API call to GitHub to get the access token URL for the installation; future calls will return the cached installation.

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) AllReposOAuth2TokenSource added in v1.1.3

func (i *AppInstallation) AllReposOAuth2TokenSource(ctx context.Context, permissions map[string]string) oauth2.TokenSource

AllReposOAuth2TokenSource creates an oauth2.TokenSource which can be used in combination with oauth2.NewClient to create an authenticated HTTP client capable of being passed to the go-github library.

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) SelectedReposOAuth2TokenSource added in v1.1.3

func (i *AppInstallation) SelectedReposOAuth2TokenSource(ctx context.Context, permissions map[string]string, repos ...string) oauth2.TokenSource

SelectedReposOAuth2TokenSource creates an oauth2.TokenSource which can be used in combination with oauth2.NewClient to create an authenticated HTTP client capable of being passed to the go-github library.

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

type Option func(g *App) *App

Option is a function that provides an option to the GitHub App creation.

func WithBaseURL added in v1.1.0

func WithBaseURL(url string) Option

WithBaseURL allows overriding of the GitHub API url. This is usually only overidden for testing or private GitHub installations.

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

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

type TokenRequestAllRepos struct {
	Permissions map[string]string `json:"permissions"`
}

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

type TokenSourceFunc func(ctx context.Context) (string, error)

TokenSourceFunc is a function that implements TokenSource.

func (TokenSourceFunc) GitHubToken

func (f TokenSourceFunc) GitHubToken(ctx context.Context) (string, error)

Jump to

Keyboard shortcuts

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