oauthrefresh

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 8 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 oauthrefresh holds the generic OAuth token-refresh machinery shared by adapters that mint short-lived access tokens (anthropic): expiry checks, single-flight refresh, control-plane persistence with retry, and snapshot re-adoption on revision conflicts. The adapter-specific HTTP exchange lives in a Refresher implementation supplied by each adapter.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSnapshotRefreshRequired signals that the control plane rejected a
	// credential persist due to a revision conflict; the gateway must re-fetch
	// the snapshot before using the refreshed credential.
	ErrSnapshotRefreshRequired = errors.New("snapshot refresh required")
	// ErrCredentialPersistenceDegraded reports that a refreshed credential is
	// in use locally but could not be persisted yet.
	ErrCredentialPersistenceDegraded = errors.New("credential persistence degraded")
)

Functions

func ShouldRefresh

func ShouldRefresh(c config.Credential, now time.Time) bool

ShouldRefresh reports whether an OAuth credential needs refreshing: empty access token, unparseable expiry, or expiry within 5 minutes.

Types

type ControlPlaneSink

type ControlPlaneSink struct{ Client *controlplane.Client }

ControlPlaneSink persists credentials through the control-plane internal credentials API.

func (ControlPlaneSink) Persist

func (s ControlPlaneSink) Persist(ctx context.Context, accountID string, expectedRevision int64, credential config.Credential) (CredentialPersistResult, error)

type CredentialPersistResult

type CredentialPersistResult struct {
	Revision int64
	Digest   string
}

type CredentialSink

type CredentialSink interface {
	Persist(context.Context, string, int64, config.Credential) (CredentialPersistResult, error)
}

CredentialSink persists refreshed OAuth credentials back to the control plane. A nil sink disables persistence (in-memory refresh only).

type Manager

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

func NewManager

func NewManager(client *http.Client, sink CredentialSink, refresh SnapshotRefreshTrigger, r Refresher) *Manager

NewManager returns a Manager that refreshes via r. The client is shared with adapters that need it (e.g. Refresher HTTP calls); it is retained on the Manager for adapter convenience.

func (*Manager) AccessToken

func (m *Manager) AccessToken(ctx context.Context, account config.Account, force bool) (config.Credential, int64, string, error)

AccessToken returns a usable OAuth credential, refreshing it when expired. force=true refreshes even when the stored token looks valid. Non-OAuth credentials are returned unchanged.

func (*Manager) Client

func (m *Manager) Client() *http.Client

Client exposes the shared HTTP client for adapters that build a Refresher around it.

type Refresher

type Refresher interface {
	Refresh(ctx context.Context, old config.Credential) (config.Credential, error)
}

Refresher performs the adapter-specific token exchange (POST to the provider's OAuth token endpoint) and returns the fresh credential.

type SnapshotRefreshTrigger

type SnapshotRefreshTrigger interface {
	TriggerSnapshotRefresh(reason string)
}

SnapshotRefreshTrigger asks the gateway to re-adopt the control-plane snapshot (used when a credential revision conflict is detected).

Jump to

Keyboard shortcuts

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