types

package
v0.77.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 1 Imported by: ? 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 types holds the upstream token reader contract.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TokenReader

type TokenReader interface {
	// GetAllUpstreamCredentials returns the access tokens (refreshing them if
	// expired) and ID tokens for every upstream provider associated with the
	// given session ID. Returns an empty map if the session has no stored
	// upstream tokens.
	//
	// The second return value maps each provider whose access token was expired
	// and could not be refreshed (e.g. the refresh token is missing or the
	// upstream IDP rejected the refresh) to the reason, using the same sentinel
	// errors as Service.GetValidTokens. Those providers are omitted from the
	// creds map. Callers should treat a non-empty failed map as a signal to
	// return HTTP 401 + WWW-Authenticate so the client can re-authenticate. An
	// upstream that definitively rejected the refresh (the IdP answered
	// invalid_grant) satisfies errors.Is(err, upstream.ErrGrantRejected); a
	// network or 5xx failure does not. When the token endpoint answered, the
	// error also carries its *oauth2.RetrieveError, so oautherr's
	// IsPermanentCredentialError tells a structured OAuth verdict (such as
	// invalid_client) from an outage (5xx, 429, or a 4xx with no OAuth code).
	// "Permanent" means only that retrying will not help: invalid_client
	// indicts the client registration, not the refresh token, so a caller
	// deciding whether to ask the user to reconnect wants
	// oautherr.IsRejectedRefreshGrant.
	//
	// Each returned IDToken is the rotated ID token when a refresh produced
	// one (OIDC Core 1.0 §12.2), otherwise the original JWT captured at OIDC
	// login (OIDC Core 1.0 §3.1.3.7), and it may be expired. Callers that PRESENT
	// it as a credential (e.g. RFC 8693 subject-token exchange) must check `exp`
	// first or handle the resulting rejection; callers that only READ ITS CLAIMS
	// are unaffected by expiry. See UpstreamCredential for both consumers.
	//
	// Returns an empty map and nil failed map (not error) for unknown sessions.
	GetAllUpstreamCredentials(ctx context.Context, sessionID string) (
		creds map[string]UpstreamCredential, failed map[string]error, err error)
}

TokenReader retrieves upstream provider credentials for a session. This narrow interface decouples the auth middleware from storage internals.

type UpstreamCredential

type UpstreamCredential struct {
	AccessToken string
	IDToken     string
}

UpstreamCredential bundles the access token and the ID token for a single upstream provider. Access tokens are refreshed when expired.

The IDToken is the rotated ID token when a refresh produced one (OIDC Core 1.0 §12.2 permits but does not require a new id_token on refresh), otherwise the original JWT captured at the initial OIDC login (OIDC Core 1.0 §3.1.3.7). InProcessService refreshes when the stored ID token has expired, so it is usually current, but it is not guaranteed to be: it can still be expired when the provider omits id_token on refresh or the refresh fails.

Callers that PRESENT it as a credential — e.g. as the subject_token of an RFC 8693 token exchange — are subject to expiry and must either check its `exp` claim first or handle the resulting rejection. Today's such consumer (pkg/vmcp/auth/strategies) deliberately takes the second option: it lets the IdP reject the exchange and surfaces the `invalid_grant`. Note also that the ID token's `aud` is this auth server's client registration with the issuing upstream, not the token-exchange endpoint — whether a target authorization server accepts it as a subject token is governed by that server's policy and is typically limited to the same issuer/audience.

Callers that only READ ITS CLAIMS are a different case and deliberately do not check `exp`: the token is then evidence of what the upstream asserted at login, and expiry says nothing about whether that assertion happened. See Identity.UpstreamIDTokens for the two consumers and why they differ.

IDToken may be empty when the upstream login did not return an id_token (e.g. the provider was not asked for the openid scope). An empty IDToken is a legitimate state, not an error. Note that Identity.UpstreamTokens and Identity.UpstreamIDTokens are projected independently and are NOT guaranteed to share the same key set: a provider with an access token but no ID token appears only in UpstreamTokens.

type UserKeyedReader

type UserKeyedReader interface {
	// UserKeyed reports whether the reader's storage is keyed by user.
	UserKeyed() bool
}

UserKeyedReader is implemented by a TokenReader that reads upstream tokens from storage keyed by user (the user-keyed layer of the embedded authorization server). auth.NewTokenValidator uses it to refuse, at startup, a validator that could not load such tokens for an interactive session.

A TokenReader that wraps another must implement it and forward the wrapped reader's answer; otherwise the validator cannot see the user-keyed storage behind it, and a misconfiguration only shows up at request time.

Jump to

Keyboard shortcuts

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