auth

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 13 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

Index

Constants

View Source
const AuthMethodOAuth = "oauth"

AuthMethodOAuth marks a credential obtained through the OAuth login flows. Credentials without an auth method are legacy opaque API tokens.

Variables

View Source
var (
	ErrNoToken        = errors.New("no token stored")
	ErrNoEmail        = errors.New("no email stored")
	ErrInvalidBackend = errors.New("invalid keyring backend")
	ErrKeyringTimeout = errors.New("keyring connection timed out")
)
View Source
var BeginPrompt = func() func() { return func() {} }

BeginPrompt marks a prompt blocked on stdin; call the returned func when the read returns. The command layer sets it so Ctrl-C ends the prompt at once (exit 130) instead of only canceling a context the read never sees. This package cannot import the command layer, hence the hook.

View Source
var ErrNoDefaultKeychain = errors.New("no default macOS keychain")

ErrNoDefaultKeychain means macOS has no default keychain for this user, as with a scratch HOME or a bare CI image. The Keychain backend would then block on a "keychain not found" dialog instead of returning an error.

Functions

func ResolveBackend

func ResolveBackend() (string, string, error)

ResolveBackend determines which keyring backend to use.

Types

type Credential

type Credential struct {
	Token        string    `json:"token"`
	Email        string    `json:"email,omitempty"`
	CreatedAt    time.Time `json:"created_at,omitempty"`
	AuthMethod   string    `json:"auth_method,omitempty"`
	RefreshToken string    `json:"refresh_token,omitempty"`
	ExpiresAt    time.Time `json:"expires_at,omitzero"`
	Scopes       []string  `json:"scopes,omitempty"`
	ClientID     string    `json:"client_id,omitempty"`
}

Credential holds stored authentication data. OAuth credentials carry a short-lived access token in Token plus the rotating refresh token; older CLI versions ignore the extra fields and keep using Token until it expires.

func (Credential) IsOAuth added in v0.4.0

func (c Credential) IsOAuth() bool

IsOAuth reports whether the credential is a refreshable OAuth session.

type HostStore added in v0.1.3

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

HostStore wraps a keyring.Keyring and keys credentials by API host, so different API endpoints have separate credential storage.

func NewHostStore added in v0.1.3

func NewHostStore(ring keyring.Keyring, host string) *HostStore

NewHostStore creates a host-scoped credential store.

func (*HostStore) DeleteCredential added in v0.1.3

func (s *HostStore) DeleteCredential() error

DeleteCredential removes credentials for this host. For the default host, also removes bare legacy keys to prevent the legacy fallback from resurrecting deleted credentials.

func (*HostStore) DeleteEmail added in v0.1.3

func (s *HostStore) DeleteEmail() error

func (*HostStore) DeleteToken added in v0.1.3

func (s *HostStore) DeleteToken() error

func (*HostStore) GetCredential added in v0.1.3

func (s *HostStore) GetCredential() (Credential, error)

GetCredential retrieves the credential for this host. For the default host, falls back to bare legacy keys and backfills.

func (*HostStore) GetEmail added in v0.1.3

func (s *HostStore) GetEmail() (string, error)

func (*HostStore) GetToken added in v0.1.3

func (s *HostStore) GetToken() (string, error)

func (*HostStore) Keys added in v0.1.3

func (s *HostStore) Keys() ([]string, error)

func (*HostStore) SetCredential added in v0.1.3

func (s *HostStore) SetCredential(cred Credential) error

SetCredential stores a credential under the host-scoped key.

func (*HostStore) SetEmail added in v0.1.3

func (s *HostStore) SetEmail(email string) error

func (*HostStore) SetToken added in v0.1.3

func (s *HostStore) SetToken(token string) error

type KeyringStore

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

KeyringStore implements Store using OS keychain.

func (*KeyringStore) DeleteCredential

func (s *KeyringStore) DeleteCredential() error

DeleteCredential removes all stored credentials.

func (*KeyringStore) DeleteEmail

func (s *KeyringStore) DeleteEmail() error

DeleteEmail removes the stored email.

func (*KeyringStore) DeleteToken

func (s *KeyringStore) DeleteToken() error

DeleteToken removes the stored token.

func (*KeyringStore) GetCredential

func (s *KeyringStore) GetCredential() (Credential, error)

GetCredential retrieves the full credential.

func (*KeyringStore) GetEmail

func (s *KeyringStore) GetEmail() (string, error)

GetEmail retrieves the stored email.

func (*KeyringStore) GetToken

func (s *KeyringStore) GetToken() (string, error)

GetToken retrieves the stored authentication token.

func (*KeyringStore) HasToken

func (s *KeyringStore) HasToken() bool

HasToken checks if a token is stored.

func (*KeyringStore) Keys

func (s *KeyringStore) Keys() ([]string, error)

Keys returns all stored keys.

func (*KeyringStore) SetCredential

func (s *KeyringStore) SetCredential(cred Credential) error

SetCredential stores a full credential (token + email + metadata).

func (*KeyringStore) SetEmail

func (s *KeyringStore) SetEmail(email string) error

SetEmail stores the user's email.

func (*KeyringStore) SetToken

func (s *KeyringStore) SetToken(token string) error

SetToken stores an authentication token.

type Store

type Store interface {
	SetCredential(cred Credential) error
	GetCredential() (Credential, error)
	DeleteCredential() error
	SetToken(token string) error
	GetToken() (string, error)
	DeleteToken() error
	SetEmail(email string) error
	GetEmail() (string, error)
	DeleteEmail() error
	Keys() ([]string, error)
}

Store provides credential storage operations.

func OpenDefault

func OpenDefault() (Store, error)

OpenDefault opens the default keyring store (no host scoping).

func OpenForHost added in v0.1.3

func OpenForHost(host string) (Store, error)

OpenForHost opens a host-scoped keyring store.

Jump to

Keyboard shortcuts

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