Help us shape the future of Go! Take the 2026 Go Developer Survey

connauth

package
v1.149.0 Latest Latest
Warning

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

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

Documentation

Overview

Package connauth assembles the connection-OAuth token lifecycle behind one Handle: the unified connection_oauth_tokens store (pkg/connoauth), the durable connection_auth_events store together with its nil-safe writer and daily 90-day prune routine (pkg/authevents), and the background token-refresh loop.

Construction is two-phase. New takes explicit inputs (a *sql.DB and the platform's *fieldcrypt.RestFieldEncryptor) and returns the assembled store + writer + auth-event store, starting the prune routine. StartRefresher builds and starts the refresh loop from an injected ConfigResolver and AdvisoryLocker: the resolver is only constructible after the per-kind OAuth handlers are wired, and the caller owns the single- vs multi-replica locker choice, so this package stays free of *sql.DB / replica config for the refresher and never imports pkg/platform.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handle

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

Handle owns the connection-OAuth token lifecycle and the goroutines behind it (the auth-event prune routine, started by New, and the background refresh loop, started by StartRefresher). The read accessors expose the token store, auth-event store, and nil-safe writer that the platform's read paths and the gateway / api-gateway toolkit wiring consume; Stop and Close are the shutdown seam the platform wires into its own lifecycle.

func New

func New(db *sql.DB, enc *fieldcrypt.RestFieldEncryptor) *Handle

New assembles the token store, the durable auth-event store and its nil-safe writer, and starts the daily 90-day prune routine. It returns nil when db is nil: the whole subsystem is a no-op without a database, matching the platform precondition (the platform falls back to the legacy per-kind in-memory stores in that case). enc may be nil (at-rest encryption disabled, dev-only) — it is passed through only when non-nil so a typed-nil interface never reaches the store's encryptor.

func (*Handle) AuthEventStore

func (h *Handle) AuthEventStore() authevents.Store

AuthEventStore returns the read-side handle for connection lifecycle events (the admin OAuth History panel), or nil on a nil Handle. Returned as the interface so callers stay off the concrete type.

func (*Handle) AuthEventWriter

func (h *Handle) AuthEventWriter() *authevents.Writer

AuthEventWriter returns the writer wrapping the auth-event store. nil-safe by contract: the Writer's methods short-circuit on a nil receiver, so every call site can pass the result straight to a component without a nil-check.

func (*Handle) Close

func (h *Handle) Close() error

Close stops the auth-event store's daily prune goroutine and waits for it. No-op on a nil Handle or when no auth-event store was wired. Idempotent: the underlying store's Close no-ops after the first call.

func (*Handle) StartRefresher

func (h *Handle) StartRefresher(resolver connoauth.ConfigResolver, locker connoauth.AdvisoryLocker)

StartRefresher builds and starts the background token-refresh loop. The caller supplies the ConfigResolver (which depends on the per-kind OAuth handlers wired after the store exists) and the AdvisoryLocker it has selected (NoopLocker single-replica, PostgresLocker multi-replica), so this package stays free of the replica-mode decision. No-op on a nil Handle, a nil resolver, or a repeat call — the refresher is built once, so a second call cannot leak the first loop's goroutine.

func (*Handle) Stop

func (h *Handle) Stop(ctx context.Context) error

Stop stops the background refresh loop, waiting up to ctx's deadline for an in-flight refresh to settle before returning. No-op on a nil Handle or when StartRefresher was never called. The caller owns the deadline (the platform bounds it to fit the K8s termination grace period).

func (*Handle) Store

func (h *Handle) Store() connoauth.Store

Store returns the unified OAuth-token store backing connection_oauth_tokens, or nil on a nil Handle (no database configured). Read by the admin unified OAuth handler and, via toolkit OAuthKindHandlers, by per-kind Authenticators.

Jump to

Keyboard shortcuts

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