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 ¶
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 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.
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).