github

package
v0.15.8 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package github is the GitHub credential provider: classic and fine-grained personal access tokens, OAuth and GitHub App tokens.

Classic tokens carry a CRC32 checksum that is verified offline, so a well-formed lookalike is never reported. Verification is one authenticated request; revocation goes through GitHub's unauthenticated endpoint for leaked credentials, which notifies the owner.

Index

Constants

View Source
const (
	// KindPAT is a classic personal access token (ghp_).
	KindPAT detect.Kind = "github-pat"
	// KindOAuth is an OAuth app access token (gho_).
	KindOAuth detect.Kind = "github-oauth"
	// KindUserToServer is a GitHub App user-to-server token (ghu_).
	KindUserToServer detect.Kind = "github-user-to-server"
	// KindServerToServer is a GitHub App installation token (ghs_).
	KindServerToServer detect.Kind = "github-server-to-server"
	// KindRefresh is a GitHub App refresh token (ghr_).
	KindRefresh detect.Kind = "github-refresh"
	// KindFineGrained is a fine-grained personal access token (github_pat_).
	KindFineGrained detect.Kind = "github-fine-grained-pat"
)

Variables

This section is empty.

Functions

func Checksum

func Checksum(random string) string

Checksum computes the 6-character Base62 CRC32 checksum GitHub appends to the 30 random characters of a classic token. Exported so callers (and tests) can construct well-formed tokens without hard-coding any.

Types

type Provider

type Provider struct {
	// BaseURL is the API root, https://api.github.com by default.
	BaseURL string
	Client  *http.Client
}

Provider implements detect.Provider for GitHub.

func New

func New() *Provider

New returns a Provider against the public GitHub API.

func (*Provider) Find

func (*Provider) Find(content []byte) []detect.Token

Find implements detect.Provider.

Two substring passes cover all six families: one for the shared "gh" stem of the classic prefixes and one for "github_pat_". Every candidate is then checked for exact shape and (classic families) checksum.

func (*Provider) Kinds

func (*Provider) Kinds() []detect.KindInfo

Kinds implements detect.Provider.

func (*Provider) LocalSources

func (*Provider) LocalSources() detect.LocalSources

LocalSources implements detect.Provider: where gh, hub, Copilot and git itself keep tokens.

func (*Provider) Name

func (*Provider) Name() string

Name implements detect.Provider.

func (*Provider) Revoke

func (p *Provider) Revoke(ctx context.Context, tokens []detect.Token) error

Revoke implements detect.Revoker through POST /credentials/revoke. The endpoint is unauthenticated on purpose: it is meant for whoever finds a token, not only its owner, and GitHub notifies the owner of every revocation. Tokens are submitted in batches the API accepts; GitHub processes them asynchronously, so a nil error means every batch was accepted, not that the tokens are already dead.

func (*Provider) Verify

func (p *Provider) Verify(ctx context.Context, tok detect.Token) detect.Verification

Verify implements detect.Provider with one authenticated request. A 401 is the only response treated as proof of revocation; anything but a clean 200 or 401 is reported as unknown.

Jump to

Keyboard shortcuts

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