jwtauth

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package jwtauth implements JWT-based authentication for BubbleFish Nexus using JWKS (JSON Web Key Set) validation. This is the "Pattern B: JWT Header Mapping (Advanced)" described in Tech Spec Section 6.6.

The middleware extracts a JWT from the Authorization: Bearer header, validates it against a cached JWKS endpoint, and maps a configurable claim (e.g. "sub") to a Nexus source name.

JWKS is fetched at startup and cached. On validation failure the cache is refreshed at most once per minute to handle key rotation.

Reference: Tech Spec Section 6.6, Phase R-20.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	JWKSUrl       string // URL to fetch the JWKS from
	ClaimToSource string // JWT claim name to map to a Nexus source (e.g. "sub")
	Audience      string // Expected "aud" claim (empty = skip audience check)
	Logger        *slog.Logger
}

Config holds JWT authentication settings.

type Result

type Result struct {
	SourceName string // value of the configured claim
	Claims     map[string]interface{}
}

Result holds the outcome of JWT validation.

type Validator

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

Validator validates JWTs against a cached JWKS.

func New

func New(cfg Config) *Validator

New creates a Validator. Call FetchJWKS() to load keys before use.

func (*Validator) FetchJWKS

func (v *Validator) FetchJWKS() error

FetchJWKS fetches the JWKS from the configured URL and caches the keys. Returns an error if the fetch or parse fails.

func (*Validator) Validate

func (v *Validator) Validate(rawToken string) (*Result, error)

Validate parses and validates a raw JWT string. On success it returns the mapped source name from the configured claim. On failure it returns an error.

If validation fails due to an unknown key ID, it attempts a JWKS refresh (at most once per minute) and retries.

Jump to

Keyboard shortcuts

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