oauthstore

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: Apache-2.0 Imports: 15 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

Overview

Package oauthstore persists opaque OAuth state without placing credentials in the filesystem in plaintext. The native keyring contains only a random master key; every record is independently authenticated and encrypted.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnavailable means the native credential service could not be used.
	// Callers should present a user action rather than silently persisting
	// credentials elsewhere.
	ErrUnavailable = errors.New("OAuth credential store unavailable")
	// ErrCorrupt means a record was present but cannot safely be decoded or
	// authenticated with the current master key.
	ErrCorrupt = errors.New("OAuth credential store record is corrupt")
	// ErrUnsafeState means a required private state path is a symlink, is not
	// owned by this user, or has insecure permissions.
	ErrUnsafeState = errors.New("unsafe OAuth credential state")
	// ErrStale means a caller tried to refresh a credential generation that
	// has since been replaced or deleted.
	ErrStale = errors.New("OAuth credential generation is stale")
	// ErrAuthorizationLocked means another process is already completing an
	// authorization flow for the same opaque credential identity.
	ErrAuthorizationLocked = errors.New("OAuth authorization is already in progress")
)

Functions

This section is empty.

Types

type Keyring

type Keyring interface {
	Get(service, account string) (string, error)
	Set(service, account, secret string) error
	Delete(service, account string) error
}

Keyring is the small subset of the native keyring used by Store. Supplying one through Options makes persistence tests independent of the host desktop keyring.

type Options

type Options struct {
	StateDir string
	Keyring  Keyring
	Random   io.Reader
}

Options controls Store dependencies. StateDir is the private Wirecmd state directory (not the OAuth subdirectory); the default follows XDG_STATE_HOME and then ~/.local/state. Random defaults to crypto/rand.Reader.

type Record

type Record struct {
	Generation string          `json:"generation"`
	Payload    json.RawMessage `json:"payload"`
}

Record is an encrypted OAuth state payload. Generation is stable across saves when supplied by the caller; Save creates one for a new record. Payload is deliberately SDK-agnostic JSON owned by the OAuth execution layer, which prevents this package from becoming an OAuth protocol shim.

type Store

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

Store provides serialized encrypted records. The identity passed to methods must be a stable, canonical byte encoding of the caller's credential scope. It is never used as a pathname or written to disk.

func New

func New() (*Store, error)

New opens a store using the standard Wirecmd state location. It performs no keyring or filesystem access until an operation is requested.

func Open

func Open(options Options) (*Store, error)

Open constructs a Store with optional test dependencies.

func (*Store) Delete

func (s *Store) Delete(identity []byte) (found bool, err error)

Delete removes a stored record. found is false when no matching record is present, including when Wirecmd has never created a master key.

func (*Store) Load

func (s *Store) Load(identity []byte) (record Record, found bool, err error)

Load retrieves one record. found is false only when no matching credentials are stored; unavailable, unsafe, and corrupted states always return an error so callers never mistake them for logged-out state.

func (*Store) LockAuthorization

func (s *Store) LockAuthorization(identity []byte) (release func(), err error)

LockAuthorization acquires a non-blocking, cross-process lease for one credential identity. The returned release function must be called when the browser flow ends. The opaque lock filename reveals neither the endpoint nor registration inputs.

func (*Store) Save

func (s *Store) Save(identity []byte, record Record) (Record, error)

Save encrypts a record and returns its resulting generation. Calling Save with an existing generation preserves that generation; an empty generation creates a fresh opaque generation for a newly authenticated record.

Jump to

Keyboard shortcuts

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