jwtjwks

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package jwtjwks implements signed JWT validation using RFC 8414 discovery and a bounded JWKS cache. Importing it registers the "jwt-jwks" authz driver.

Index

Constants

View Source
const DriverName = "jwt-jwks"

DriverName is the name this validator driver registers under.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// AllowedAlgorithms is mandatory and limits both JWT headers and usable JWKs.
	AllowedAlgorithms []string     `json:"allowed_algorithms"`
	HTTPClient        *http.Client `json:"-"`
	// MaxResponseBytes bounds each discovery or JWKS document (default 1 MiB).
	MaxResponseBytes int64 `json:"max_response_bytes,omitempty"`
	// MaxKeys bounds the number of keys in one JWKS document (default 32).
	MaxKeys int `json:"max_keys,omitempty"`
	// CacheTTL controls successful JWKS retention (default 15 minutes).
	CacheTTL time.Duration `json:"cache_ttl,omitempty"`
	// RefreshCooldown rate-limits repeated JWKS refresh attempts (default 5 seconds).
	RefreshCooldown time.Duration `json:"refresh_cooldown,omitempty"`
	// ClockSkew is JWT time-claim leeway (default zero).
	ClockSkew time.Duration    `json:"clock_skew,omitempty"`
	Now       func() time.Time `json:"-"`
}

Config controls bounded discovery and key caching. Zero values receive secure defaults. AllowedAlgorithms must explicitly contain only RS256, RS384, RS512, ES256, ES384, or ES512. MaxResponseBytes is constrained to 1 KiB..4 MiB, MaxKeys to 1..128, CacheTTL to 1 second..24 hours, RefreshCooldown to 1 second..5 minutes, and ClockSkew to 0..5 minutes.

type Validator

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

Validator is safe for concurrent validation and key rotation.

func New

func New(ctx context.Context, issuer, resource string, cfg Config) (*Validator, error)

New discovers the configured issuer and primes its JWKS cache.

func (*Validator) Validate

func (v *Validator) Validate(ctx context.Context, token string) (authz.Principal, error)

Validate verifies signature, exact algorithm/issuer/audience, subject and time claims. Returned errors never include token or claim values.

Jump to

Keyboard shortcuts

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