tokenexpiry

package
v1.167.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 2 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 tokenexpiry gives an access token whose token endpoint stated no expires_in an expiry to be held against (#1737). It knows nothing about connections: internal/upstreamauth wraps the client_credentials and jwt_bearer token sources in it, with the lifetime the connection sets as oauth_token_lifetime (#2218).

Index

Constants

View Source
const DefaultLifetime = 15 * time.Minute

DefaultLifetime is how long an access token from a token endpoint is reused when the response carries no expires_in and the connection sets no oauth_token_lifetime. RFC 6749 section 5.1 makes expires_in RECOMMENDED rather than required, and golang.org/x/oauth2 treats a token with a zero Expiry as valid forever (oauth2.Token.expired returns false when Expiry.IsZero), so an upstream that omits it would otherwise have its first access token presented for the life of the process: once the session behind that token ended, every call through the connection would fail with the upstream's 401 until the connection was saved again or the replica restarted.

Obtaining a token is unattended and costs one request, so a window this short bounds how long an ended session can go unnoticed for little cost: a connection nobody calls fetches nothing, and a busy one fetches four times an hour per replica.

Variables

This section is empty.

Functions

func Bounded

func Bounded(src oauth2.TokenSource, now func() time.Time, lifetime time.Duration) oauth2.TokenSource

Bounded wraps src so a token it returns with no expiry is reused for lifetime rather than forever; zero or less is DefaultLifetime. A token that carries an expiry is passed through untouched: the upstream's own lifetime always wins, including one shorter than the window.

Types

type Func

type Func func() (*oauth2.Token, error)

Func adapts a bare fetch into an oauth2.TokenSource, for a grant whose fetch is a function rather than a type. It caches nothing: the one cache is the oauth2.ReuseTokenSource wrapping the bounded source above it.

func (Func) Token

func (f Func) Token() (*oauth2.Token, error)

Token calls the function.

Jump to

Keyboard shortcuts

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