Documentation
¶
Overview ¶
Package verifier provides multi-issuer JWT verification for lakta services.
A Registry holds one JWKS-backed verifier per configured issuer (keyed by the exact iss claim) plus an isolated HS256 static-key dev path, and exposes a single Verify entry point the fiber and grpc auth adapters call. Every verification failure surfaces as an opaque errors.Unauthenticated; the package never reveals which check failed.
Index ¶
- func ContextWithPrincipal(ctx context.Context, p *Principal) context.Context
- type Config
- type IssuerConfig
- type Module
- func (m *Module) ConfigPath() string
- func (m *Module) Dependencies() ([]reflect.Type, []reflect.Type)
- func (m *Module) Init(ctx context.Context) error
- func (m *Module) LoadConfig(k *koanf.Koanf) error
- func (m *Module) OnReload(k *koanf.Koanf)
- func (m *Module) Provides() []reflect.Type
- func (m *Module) Shutdown(_ context.Context) error
- type Option
- type Principal
- type Registry
- type StaticKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Name string `koanf:"-"`
Issuers []IssuerConfig `koanf:"issuers"`
StaticKey *StaticKey `koanf:"static_key"`
ScopeClaim string `koanf:"scope_claim"`
RolesClaim string `koanf:"roles_claim"`
}
Config is unmarshaled from modules.auth.verifier.<instance>.
func NewDefaultConfig ¶
func NewDefaultConfig() Config
NewDefaultConfig returns default configuration.
type IssuerConfig ¶
type IssuerConfig struct {
// Issuer is matched against the token iss exactly (no prefix/substring).
Issuer string `koanf:"issuer"`
// Audience MUST be non-empty; the token aud must intersect it.
Audience []string `koanf:"audience"`
// JWKSURL is the JWKS endpoint; empty triggers OIDC discovery from Issuer.
JWKSURL string `koanf:"jwks_url"`
// Algorithms is a hard allowlist, e.g. [RS256, ES256]; alg:none is rejected.
Algorithms []string `koanf:"algorithms"`
// ClockSkew is capped at maxClockSkew.
ClockSkew time.Duration `koanf:"clock_skew"`
}
IssuerConfig is one trusted JWKS/OIDC issuer.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module provides a *Registry at modules.auth.verifier.<instance> via DI.
func (*Module) ConfigPath ¶
ConfigPath returns the koanf path for this module's configuration.
func (*Module) Dependencies ¶
Dependencies declares the optional types this module needs from DI before Init.
func (*Module) LoadConfig ¶
LoadConfig loads configuration from koanf.
func (*Module) OnReload ¶
OnReload rebuilds the verifiers only when issuers/audience/static_key (or the claim paths) change; JWKS rotation is already automatic via the cache.
type Principal ¶
type Principal struct {
Subject string
Issuer string
Audience []string
Scopes []string
Roles []string
Claims map[string]any
Token jwt.Token
}
Principal is the verified identity the adapters stash in the request context after a successful Registry.Verify.
func PrincipalFrom ¶
PrincipalFrom returns the Principal placed in ctx by the adapters, and false when the request is anonymous.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds one verifier per configured issuer plus the isolated static-key verifier. It is the single entry point both adapters call.