tokenstore

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(key, data []byte) ([]byte, error)

Decrypt decrypts data produced by Encrypt using the given 32-byte key.

func Encrypt

func Encrypt(key, plaintext []byte) ([]byte, error)

Encrypt encrypts plaintext with AES-256-GCM using the given 32-byte key. Returns nonce (12 bytes) || ciphertext || GCM tag (16 bytes).

func MarshalTokenInfo

func MarshalTokenInfo(ti TokenInfo) ([]byte, error)

MarshalTokenInfo serializes TokenInfo to JSON.

Types

type KeyringStore

type KeyringStore struct{}

KeyringStore persists tokens in the system keyring (macOS Keychain, Linux Secret Service, Windows Credential Manager).

func (*KeyringStore) Available

func (s *KeyringStore) Available() bool

Available returns true if the system keyring is accessible.

func (*KeyringStore) Delete

func (s *KeyringStore) Delete(name string) error

func (*KeyringStore) Load

func (s *KeyringStore) Load(name string) (TokenInfo, error)

func (*KeyringStore) Save

func (s *KeyringStore) Save(name string, ti TokenInfo) error

type MachineStore

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

MachineStore encrypts tokens with a key derived from machine identity + random salt.

func NewMachineStore

func NewMachineStore(configDir string) *MachineStore

NewMachineStore creates a MachineStore.

func (*MachineStore) Delete

func (s *MachineStore) Delete(name string) error

func (*MachineStore) Load

func (s *MachineStore) Load(name string) (TokenInfo, error)

func (*MachineStore) Save

func (s *MachineStore) Save(name string, ti TokenInfo) error

type SSHAgentStore

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

SSHAgentStore encrypts tokens using key material derived from an SSH agent signature.

func NewSSHAgentStore

func NewSSHAgentStore(configDir string) (*SSHAgentStore, error)

NewSSHAgentStore creates an SSHAgentStore if an SSH agent is available.

func (*SSHAgentStore) Delete

func (s *SSHAgentStore) Delete(name string) error

func (*SSHAgentStore) Load

func (s *SSHAgentStore) Load(name string) (TokenInfo, error)

func (*SSHAgentStore) Save

func (s *SSHAgentStore) Save(name string, ti TokenInfo) error

type TokenInfo

type TokenInfo struct {
	RefreshToken string    `json:"refresh_token"`
	AccessToken  string    `json:"access_token"`
	ExpiresAt    time.Time `json:"expires_at,omitempty"`
	Scope        string    `json:"scope,omitempty"`
	// Server is the origin (scheme://host:port) of the server the token was issued for; empty for tokens saved
	// before this field existed.
	Server string `json:"server,omitempty"`
	// Sequence is only read to detect tokens of the legacy /auth/cli sign-in; never written.
	Sequence string `json:"sequence,omitempty"`
}

TokenInfo holds the token data persisted across sessions.

func UnmarshalTokenInfo

func UnmarshalTokenInfo(data []byte) (TokenInfo, error)

UnmarshalTokenInfo deserializes TokenInfo from JSON.

func (TokenInfo) IssuedFor added in v1.3.0

func (t TokenInfo) IssuedFor(origin string) bool

IssuedFor reports whether the token may be sent to the server of the given origin: a token saved for another server never is; a token without Server (saved before the field existed) is accepted unless legacy.

func (TokenInfo) Legacy added in v1.3.0

func (t TokenInfo) Legacy() bool

Legacy reports a token of the legacy sign-in (it has a sequence), which the OAuth flow cannot refresh.

type TokenStore

type TokenStore interface {
	Load(name string) (TokenInfo, error)
	Save(name string, ti TokenInfo) error
	Delete(name string) error
}

TokenStore abstracts token persistence across backends.

func NewTokenStore

func NewTokenStore(configDir string) TokenStore

NewTokenStore returns the best available token storage backend. Priority: system keyring > SSH agent > machine-bound encryption.

Jump to

Keyboard shortcuts

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