auth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

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

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"`
}

Credential holds stored authentication data.

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