auth

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrGhNotInstalled = errors.New("the GitHub CLI (gh) is required but not installed; install it from https://cli.github.com/ and run 'gh auth login'")

ErrGhNotInstalled indicates the gh CLI is not in PATH.

Functions

This section is empty.

Types

type CommandRunner

type CommandRunner func(name string, args ...string) ([]byte, error)

CommandRunner executes external commands. Swappable for testing.

type ErrNoToken

type ErrNoToken struct {
	Domain string
}

ErrNoToken indicates no token could be resolved for a domain.

func (*ErrNoToken) Error

func (e *ErrNoToken) Error() string

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider resolves and caches GitHub tokens for the process lifetime.

func NewProvider

func NewProvider() *Provider

NewProvider creates a Provider with the default command runner.

func NewProviderWithRunner

func NewProviderWithRunner(runner CommandRunner) *Provider

NewProviderWithRunner creates a Provider with a custom command runner (for testing).

func (*Provider) DetectToken

func (p *Provider) DetectToken(domain string) (*Token, error)

DetectToken resolves a token for the given domain.

Resolution order:

  1. GITHUB_TOKEN env var — used for ALL domains, including GitHub Enterprise.
  2. gh auth token --hostname <domain> — domain-specific token from gh CLI.

GITHUB_TOKEN intentionally applies to every domain, not just github.com. This differs from the gh CLI itself, which uses GH_ENTERPRISE_TOKEN for GHE. The rationale: work delegates auth to gh and treats GITHUB_TOKEN as a universal override for CI/CD and automation. Users needing per-domain tokens should use gh auth login --hostname <domain> for each host instead of the env var.

Results are cached in memory for the process lifetime.

func (*Provider) TokenForDomain

func (p *Provider) TokenForDomain(domain string) (string, error)

TokenForDomain resolves a token for the given domain and returns just the token string. Convenience wrapper around DetectToken for callers that don't need the token source metadata.

type Token

type Token struct {
	Value  string
	Source TokenSource
}

Token holds a resolved token and its source.

type TokenSource

type TokenSource string

TokenSource describes where a token was resolved from.

const (
	TokenSourceEnv   TokenSource = "GITHUB_TOKEN"
	TokenSourceGhCLI TokenSource = "gh"
)

Jump to

Keyboard shortcuts

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