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

token

package
v0.24.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// DefaultRefreshLead is the default lead for every registry and inline
	// provider, including the workspace provider.
	DefaultRefreshLead = 15 * time.Minute
	// MinUsefulRefreshLead is the minimum effective lead; below it a refresh
	// would race the token's own expiry.
	MinUsefulRefreshLead = 30 * time.Second
)

Refresh policy shared by request-time resolution and the background refresh watcher. Both must call the same ShouldRefresh decision; they must not maintain different thresholds.

Variables

This section is empty.

Functions

func EffectiveRefreshLead

func EffectiveRefreshLead(configured, lifetime time.Duration) time.Duration

EffectiveRefreshLead computes the refresh lead applied to one token:

effectiveRefreshLead = min(configuredRefreshLead, originalTokenLifetime * 20%)
minimum useful lead  = 30 seconds

configured <= 0 selects DefaultRefreshLead. lifetime <= 0 means the original token lifetime is unavailable: the configured lead is used unchanged and the caller must enforce a per-token refresh cooldown instead.

func IsRefreshInvalidGrant

func IsRefreshInvalidGrant(err error) bool

IsRefreshInvalidGrant reports whether err carries invalid_grant classification from the OAuth refresh broker.

func NewRefreshInvalidGrantError

func NewRefreshInvalidGrantError(cause error) error

NewRefreshInvalidGrantError wraps a parsed invalid_grant response.

func RefreshJitter

func RefreshJitter(key Key, lead time.Duration) time.Duration

RefreshJitter derives a small deterministic per-key offset (up to 10% of lead) so multiple pods and users do not refresh simultaneously. Determinism keeps request-time and background decisions for the same key identical.

func ShouldRefresh

func ShouldRefresh(now, expiresAt time.Time, configured, lifetime time.Duration) bool

ShouldRefresh reports whether a token expiring at expiresAt should refresh now under the provider's configured lead and the token's original lifetime. Tokens without a known expiry never trigger refresh.

Types

type InstanceID

type InstanceID string

InstanceID uniquely identifies a running process instance (hostname:pid:uuid). The UUID suffix handles container recycling where hostname+PID may be reused.

func NewInstanceID

func NewInstanceID() InstanceID

NewInstanceID creates a new InstanceID for the current process.

type Key

type Key struct {
	Subject  string // user identifier (from EffectiveUserID)
	Provider string // oauth provider name (e.g. "google", "default")
}

Key identifies a token set for a user+provider pair.

type RefreshInvalidGrantError

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

RefreshInvalidGrantError classifies a parsed invalid_grant response from the OAuth token endpoint without coupling the token manager to service/auth.

func (*RefreshInvalidGrantError) Error

func (e *RefreshInvalidGrantError) Error() string

func (*RefreshInvalidGrantError) Unwrap

func (e *RefreshInvalidGrantError) Unwrap() error

Jump to

Keyboard shortcuts

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