tokencache

package
v0.3.1 Latest Latest
Warning

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

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

This section is empty.

Variables

View Source
var (
	ErrAmbiguousAccount = errors.New("multiple cached accounts; specify --email")
)

Functions

func Clear

func Clear(id Identity) error

Clear removes the identity's local token cache from reachable backends. An unavailable backend is tolerated if another opens, but removal failures from an opened backend are returned. This does not revoke tokens at the service.

func Save

func Save(id Identity, token string, expiresAt time.Time, userID string) error

func SetFallbackPathForTest

func SetFallbackPathForTest(path string) (restore func())

SetFallbackPathForTest isolates legacy plaintext-cache migration tests. Production code uses the default location only to remove pre-upgrade entries.

func SetOpenFileKeyringForTest

func SetOpenFileKeyringForTest(fn func() (keyring.Keyring, error)) (restore func())

SetOpenFileKeyringForTest swaps the file-backed fallback opener. Use with SetOpenKeyringForTest to exercise the fallback path in isolation.

func SetOpenKeyringForTest

func SetOpenKeyringForTest(fn func() (keyring.Keyring, error)) (restore func())

SetOpenKeyringForTest swaps the keyring opener; it returns a restore func. Not safe for concurrent tests; intended for isolated test scenarios.

Types

type CachedToken

type CachedToken struct {
	Token     string    `json:"token"`
	ExpiresAt time.Time `json:"expires_at"`
	UserID    string    `json:"user_id,omitempty"`
}

func Load

func Load(id Identity) (*CachedToken, error)

Load returns the cached token for the given Identity, if present and unexpired. Tokens are namespaced by Identity (base URL + client ID + email) — not by UserID — because a single OAuth principal (email) can legitimately act on multiple household userIDs. The cached UserID is informational metadata for callers that want to recover "which userID was primary at auth time."

type Identity

type Identity struct {
	BaseURL  string
	ClientID string
	Email    string
}

Identity describes the authentication context a token belongs to. Tokens are namespaced by base URL, client ID, and email so switching between accounts or environments doesn't reuse the wrong credentials.

Jump to

Keyboard shortcuts

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