{"modulePath":"github.com/abcxyz/pkg","version":"v1.5.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package githubauth\n\nPackage githubauth provides interfaces and implementations for authenticating to GitHub.\n\n## Functions\n\n```go\nfunc NewPrivateKeySigner[T *rsa.PrivateKey | string | []byte](privateKeyT T) (crypto.Signer, error)\n```\nNewPrivateKeySigner utilizes a private key that is provided directly to sign requests. The private key can be an actual rsa.Private or a string / byte\\[] representation of the key.\n\n## Types\n\n```go\ntype App struct {\n\t// contains filtered or unexported fields\n}\n```\nApp is an object that can be used to generate application level JWTs or to request an OIDC token on behalf of an installation.\n\n```go\nfunc NewApp(appID string, signer crypto.Signer, opts ...Option) (*App, error)\n```\nNewApp creates a new GitHub App from the given inputs.\n\nThe signer can be any crypto.Signer. For RSA keys or PEM-encoded strings of RSA keys, use [NewPrivateKeySigner](#NewPrivateKeySigner). For Google Cloud KMS, use a signer implementation like [github.com/sethvargo/go-gcpkms/pkg/gcpkms.NewSigner](/github.com/sethvargo/go-gcpkms/pkg/gcpkms#NewSigner):\n\n\tclient, err := kms.NewKeyManagementClient(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to setup client: %w\", err)\n\t}\n\tsigner, err := gcpkms.NewSigner(ctx, client, keyID)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create signer: %w\", err)\n\t}\n\treturn signer, nil\n\n```go\nfunc (a *App) AppID() string\n```\nAppID returns the GitHub App's ID.\n\n```go\nfunc (g *App) AppToken() (string, error)\n```\nAppToken creates a signed JWT to authenticate a GitHub app so that it can make API calls to GitHub.\n\n```go\nfunc (a *App) InstallationForID(ctx context.Context, installationID string) (*AppInstallation, error)\n```\nInstallationForID returns an AccessTokensURLFunc that gets the access token url for the given installation.\n\nThe 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.\n\n```go\nfunc (a *App) InstallationForOrg(ctx context.Context, org string) (*AppInstallation, error)\n```\nInstallationForOrg returns an AccessTokensURLFunc that gets the access token url for the given org context.\n\nThe 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.\n\n```go\nfunc (a *App) InstallationForRepo(ctx context.Context, org, repo string) (*AppInstallation, error)\n```\nInstallationForRepo returns an AccessTokensURLFunc that gets the access token url for the given repo context.\n\nThe 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.\n\n```go\nfunc (a *App) InstallationForUser(ctx context.Context, user string) (*AppInstallation, error)\n```\nInstallationForUser returns an AccessTokensURLFunc that gets the access token url for the given user context.\n\nThe 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.\n\n```go\nfunc (a *App) OAuthAppTokenSource() oauth2.TokenSource\n```\nOAuthAppTokenSource adheres to the oauth2 TokenSource interface and returns a oauth2 token by creating a JWT token.\n\n```go\ntype AppInstallation struct {\n\t// contains filtered or unexported fields\n}\n```\nAppInstallation represents a specific installation of the app (on a repo, org, or user).\n\n```go\nfunc (i *AppInstallation) AccessToken(ctx context.Context, request *TokenRequest) (string, error)\n```\nAccessToken calls the GitHub API to generate a new access token for this application installation with the requested permissions and repositories.\n\n```go\nfunc (i *AppInstallation) AccessTokenAllRepos(ctx context.Context, request *TokenRequestAllRepos) (string, error)\n```\nAccessTokenAllRepos calls the GitHub API to generate a new access token for this application installation with the requested permissions and all granted repositories.\n\n```go\nfunc (i *AppInstallation) AllReposOAuth2TokenSource(ctx context.Context, permissions map[string]string) oauth2.TokenSource\n```\nAllReposOAuth2TokenSource creates an [oauth2.TokenSource](/golang.org/x/oauth2#TokenSource) which can be used in combination with [oauth2.NewClient](/golang.org/x/oauth2#NewClient) to create an authenticated HTTP client capable of being passed to the go-github library.\n\n```go\nfunc (i *AppInstallation) AllReposTokenSource(permissions map[string]string) TokenSource\n```\nAllReposTokenSource returns a [TokenSource](#TokenSource) that mints a GitHub token with permissions on all repos.\n\n```go\nfunc (i *AppInstallation) App() *App\n```\nApp returns the underlying app for this installation. This is a pointer back to the exact [App](#App) that created the installation, meaning callers cannot assume exclusive ownership over the result.\n\n```go\nfunc (i *AppInstallation) SelectedReposOAuth2TokenSource(ctx context.Context, permissions map[string]string, repos ...string) oauth2.TokenSource\n```\nSelectedReposOAuth2TokenSource creates an [oauth2.TokenSource](/golang.org/x/oauth2#TokenSource) which can be used in combination with [oauth2.NewClient](/golang.org/x/oauth2#NewClient) to create an authenticated HTTP client capable of being passed to the go-github library.\n\n```go\nfunc (i *AppInstallation) SelectedReposTokenSource(permissions map[string]string, repos ...string) TokenSource\n```\nSelectedReposTokenSource returns a [TokenSource](#TokenSource) that mints a GitHub token with permissions on the selected repos.\n\n```go\ntype Option func(g *App) *App\n```\nOption is a function that provides an option to the GitHub App creation.\n\n```go\nfunc WithBaseURL(url string) Option\n```\nWithBaseURL allows overriding of the GitHub API url. This is usually only overidden for testing or private GitHub installations.\n\n```go\nfunc WithHTTPClient(client *http.Client) Option\n```\nWithHTTPClient is an option that allows a consumer to provider their own http client implementation. This HTTP client will be shared among all [AppInstallation](#AppInstallation).\n\n```go\ntype StaticTokenSource struct {\n\t// contains filtered or unexported fields\n}\n```\nStaticTokenSource is a GitHubToken provider that returns the provided token.\n\n```go\nfunc NewStaticTokenSource(token string) (*StaticTokenSource, error)\n```\nNewStaticTokenSource returns a [StaticTokenSource](#StaticTokenSource) which returns the token string as given.\n\n```go\nfunc (s *StaticTokenSource) GitHubToken(ctx context.Context) (string, error)\n```\nGitHubToken implements [TokenSource](#TokenSource).\n\n```go\ntype TokenRequest struct {\n\tRepositories []string          `json:\"repositories\"`\n\tPermissions  map[string]string `json:\"permissions\"`\n}\n```\nTokenRequest is a struct that contains the list of repositories and the requested permissions / scopes that are requested when generating a new installation access token.\n\n```go\ntype TokenRequestAllRepos struct {\n\tPermissions map[string]string `json:\"permissions\"`\n}\n```\nTokenRequestAllRepos is a struct that contains the requested permissions/scopes that are requested when generating a new installation access token.\n\nThis struct intentionally omits the repository properties to generate a token for all repositories granted to this GitHub app installation.\n\n```go\ntype TokenSource interface {\n\t// GitHubToken returns a GitHub token, or any error that occurs.\n\tGitHubToken(ctx context.Context) (string, error)\n}\n```\nTokenSource is an interface which returns a GitHub token.\n\n```go\ntype TokenSourceFunc func(ctx context.Context) (string, error)\n```\nTokenSourceFunc is a function that implements [TokenSource](#TokenSource).\n\n```go\nfunc (f TokenSourceFunc) GitHubToken(ctx context.Context) (string, error)\n```\n\n","path":"github.com/abcxyz/pkg/githubauth","name":"githubauth","synopsis":"Package githubauth provides interfaces and implementations for authenticating to GitHub.","isRedistributable":true}
