Documentation
¶
Overview ¶
Package jwt issues and verifies JWT access tokens (RFC 7519, RFC 9068) using only the standard library.
Only two algorithms exist: HS256 and EdDSA (Ed25519). Every key is pinned to one algorithm through keys.Key.Alg, and the verifier looks the key up by "kid" and requires the token's "alg" to match it. "none", RSA and ECDSA are never accepted, which rules out algorithm-confusion attacks by construction.
Index ¶
Constants ¶
const ( // DefaultTTL is the access-token lifetime when Config.TTL is zero. DefaultTTL = 10 * time.Minute // DefaultLeeway is the clock-skew allowance when Config.Leeway is zero. DefaultLeeway = 30 * time.Second // MaxLeeway caps Config.Leeway. MaxLeeway = 2 * time.Minute // MaxTokenSize is the largest token the verifier will parse. MaxTokenSize = 8 << 10 // TokenType is the "typ" header for access tokens (RFC 9068). TokenType = "at+jwt" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Issuer string // "iss"; required
Audience string // "aud"; required
TTL time.Duration // issuer only; DefaultTTL if zero
Leeway time.Duration // verifier only; DefaultLeeway if zero, at most MaxLeeway
// Now returns the current time. Nil means time.Now. Useful in tests.
Now func() time.Time
}
Config holds the settings shared by Issuer and Verifier.
type Issuer ¶
type Issuer struct {
// contains filtered or unexported fields
}
Issuer issues JWT access tokens signed with the provider's active key.
The active key is read on every call, so rotating the provider takes effect for the next token issued.
type Verifier ¶
type Verifier struct {
// contains filtered or unexported fields
}
Verifier verifies JWT access tokens.
Checks, in order: size and shape, header ("typ" must be at+jwt, "kid" must name a known key, "alg" must equal that key's pinned algorithm), signature, then claims ("iss", "aud", "exp", "nbf", "iat" with leeway, non-empty "sub").
func NewVerifier ¶
NewVerifier creates a JWT verifier.