jwtutil

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 17 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

Index

Constants

This section is empty.

Variables

View Source
var ErrAlgorithm = errors.New("token algorithm does not match its key")

Error of a token whose signing algorithm differs from the one its key is published for

View Source
var ErrKeyNotFound = errors.New("jwk set has no matching signing key")

Error of a key lookup the JWK set has no signing key for, wrapped with the key id asked for

View Source
var ErrNoKeys = errors.New("jwk set has no usable signing keys")

Error of a JWK set that holds no key able to verify signatures

Functions

This section is empty.

Types

type FetchError

type FetchError struct {
	URL        string
	StatusCode int
	Err        error
}

Failed fetch of a JWK set: its address, the HTTP status when the server answered with an error status, else the transport or decoding error

func (*FetchError) Error

func (e *FetchError) Error() string

The address and what went wrong, as in fetch jwk set https://example.com/keys: 503 Service Unavailable

func (*FetchError) Unwrap

func (e *FetchError) Unwrap() error

Transport or decoding error of the fetch, nil for an error status

type JWKClient

type JWKClient struct {
	URL        string
	Header     http.Header
	HTTP       *http.Client
	Timeout    time.Duration
	Lifespan   time.Duration
	MinRefresh time.Duration
	// contains filtered or unexported fields
}

Cached view of a JWK set endpoint, safe for concurrent use: Header is sent with each fetch, HTTP fetches (http.DefaultClient when nil), Timeout bounds one fetch (30 seconds when zero), Lifespan is how long a fetched set serves before a lookup renews it in the background (5 minutes when zero), MinRefresh is the shortest gap after which an unknown key id or a failed refresh fetches again (30 seconds when zero); set the fields before the first lookup

func NewJWKClient

func NewJWKClient(url string) *JWKClient

Client of the JWK set at url with the default timeout, lifespan and refresh gap

func (*JWKClient) Key

func (c *JWKClient) Key(ctx context.Context, kid string) (*Key, error)

Signing key with key id kid, or the only signing key of the set when kid is empty and the set has exactly one; the cached set answers at once, past its lifespan too while a background fetch renews it or after that fetch failed, and an unknown kid waits for a fetch of the set once MinRefresh has passed since the last one

func (*JWKClient) Keyfunc

func (c *JWKClient) Keyfunc(ctx context.Context) jwt.Keyfunc

Key function for jwt parsing: the public key the token's kid header names, every signing key that fits the token's algorithm when the kid header is absent or empty, an error for a key published for another algorithm or of a type the algorithm cannot verify with

func (*JWKClient) Keys

func (c *JWKClient) Keys(ctx context.Context) ([]*Key, error)

Every signing key of the set, cached and refreshed as Key does

type Key

type Key struct {
	ID        string
	Use       string
	Algorithm string
	Public    any
	Params    map[string]any
}

One usable key of a JWK set: its key id, use and algorithm (each empty when the set leaves it out), the public key (*rsa.PublicKey, *ecdsa.PublicKey, ed25519.PublicKey, or the []byte secret of an oct key) and every member of the key as published

Jump to

Keyboard shortcuts

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