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