Help us shape the future of Go! Take the 2026 Go Developer Survey

setjwt

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package setjwt parses and validates RFC 8417 Security Event Tokens. It has no authsome dependencies. Errors are the RFC 8935 sentinels so a caller can turn a failure straight into a push-endpoint error body.

Index

Constants

View Source
const MaxJTILength = 255

MaxJTILength bounds the jti we are willing to store as a dedupe key.

Variables

View Source
var (
	ErrInvalidRequest  = errors.New("setjwt: invalid_request")
	ErrInvalidKey      = errors.New("setjwt: invalid_key")
	ErrInvalidIssuer   = errors.New("setjwt: invalid_issuer")
	ErrInvalidAudience = errors.New("setjwt: invalid_audience")
)

RFC 8935 error sentinels. ErrCode turns one into its wire code.

View Source
var ErrKeyUnavailable = errors.New("setjwt: key set unavailable")

ErrKeyUnavailable says the key set could not be loaded, so the token was never actually checked. It is deliberately NOT one of the RFC 8935 codes: none of them describe "our side could not look", and every one of them tells a well-behaved transmitter that the token is wrong and retrying is pointless. A caller that sees this must answer with a 5xx and let the transmitter deliver the same SET again.

A KeyResolver signals it by returning an error that wraps this sentinel; Validate passes such an error through instead of flattening it into ErrInvalidKey. A resolver that just cannot find the kid keeps returning a plain error and still gets invalid_key, which is the right permanent answer for a token naming a key the issuer does not publish.

Functions

func ErrCode

func ErrCode(err error) string

ErrCode maps an error to its RFC 8935 code, defaulting to invalid_request.

func Header(raw []byte) (kid, alg, typ string, err error)

Header reads kid, alg and typ without verifying anything. Use it only to pick a key and to reject an algorithm before doing real work.

Types

type KeyResolver

type KeyResolver interface {
	Key(ctx context.Context, kid string) (crypto.PublicKey, error)
}

KeyResolver hands back the public key for a kid.

type Options

type Options struct {
	Issuer    string
	Audience  string
	Keys      KeyResolver
	Now       func() time.Time
	MaxAge    time.Duration
	ClockSkew time.Duration
	MaxEvents int
}

Options configures Validate. Every field is required.

type Token

type Token struct {
	Issuer   string
	Audience []string
	JTI      string
	IssuedAt time.Time
	Events   map[string]json.RawMessage
}

Token is a validated SET.

func Validate

func Validate(ctx context.Context, raw []byte, opts Options) (*Token, error)

Validate verifies a SET end to end and returns it. The claim checks run after signature verification, so nothing in the token is trusted until the key that the caller pinned has vouched for it.

Jump to

Keyboard shortcuts

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