Skip to content

Config ​

Config ​

go
type Config struct {
    SecretKey       string
    SigningKey      any
    VerificationKey any
    SigningMethod   SigningMethod

    AccessTokenTTL        time.Duration
    RefreshTokenTTL       time.Duration
    Issuer                string
    ExpectedAudience      string
    RequireExpiration     bool
    RejectRefreshAsAccess bool
    RotateRefreshTokens   bool
    ClockSkew             time.Duration

    Blacklist BlacklistConfig

    EnableRateLimit bool
    RateLimitRate   int
    RateLimitWindow time.Duration
    RateLimiter     RateLimitProvider

    Clock ClockProvider
}

Unified configuration for the JWT Processor. Zero-value fields are automatically populated with defaults in New() (via normalizeConfig).

Auto-fill Rules

  • RateLimitRate and RateLimitWindow are only populated when EnableRateLimit = true
  • Built-in blacklist store's EnableAutoCleanup is always forced to true (to prevent unbounded growth)
  • SecretKey, SigningKey, and VerificationKey are not auto-populated; they must be set manually
struct

Fields ​

FieldTypeDefaultDescription
SecretKeystring—HMAC key (at least 32 bytes)
SigningKeyany—Asymmetric algorithm private key (*rsa.PrivateKey or *ecdsa.PrivateKey)
VerificationKeyany—Asymmetric algorithm public key (optional, defaults to SigningKey)
SigningMethodSigningMethodHS256Signing algorithm
AccessTokenTTLtime.Duration15mAccess token time-to-live
RefreshTokenTTLtime.Duration168hRefresh token time-to-live
Issuerstring"jwt-service"Issuer
ExpectedAudiencestring—Expected audience (optional)
RequireExpirationboolfalseWhen true, rejects tokens lacking an exp claim during validation (returns ErrExpirationRequired)
RejectRefreshAsAccessboolfalse(New in v1.2.3) When true, Parse / ParseInto reject token_type=refresh tokens being used as access credentials (returns ErrTokenTypeMismatch); Refresh / RefreshInto are never affected
RotateRefreshTokensboolfalse(New in v1.2.3) When true, Refresh / RefreshInto revoke the supplied refresh token (by jti) before minting the new token, giving one-time-use semantics (fail-closed: revocation failure returns ErrRefreshRotationFailed; a missing jti returns ErrTokenMissingID). See Token Refresh & Rotation
ClockSkewtime.Duration0Clock skew leeway applied to exp/nbf during validation (tolerates clock drift between issuer and validator); negative values are rejected by Validate()
BlacklistBlacklistConfig—Blacklist configuration
EnableRateLimitboolfalseEnable rate limiting
RateLimitRateint100Max requests per window
RateLimitWindowtime.Duration1mRate limit window
RateLimiterRateLimitProvider—Custom rate limiter (optional)
ClockClockProviderSystemClock{}Clock provider

Methods ​

MethodSignatureDescription
Validatefunc (c *Config) Validate() errorValidates configuration

Validate() checks:

CheckDescription
Signing keysHMAC requires SecretKey ≥32 bytes and non-weak; RSA/ECDSA requires correct SigningKey type; ECDSA requires curve match; VerificationKey must match algorithm public key type
TTL validityAccessTokenTTL and RefreshTokenTTL must be positive
TTL orderingAccessTokenTTL must be less than RefreshTokenTTL
ClockSkewClockSkew must not be negative
Signing algorithmMust be one of the 12 built-in algorithms
BlacklistBuilt-in store requires positive MaxSize and CleanupInterval

BlacklistConfig ​

go
type BlacklistConfig struct {
    CleanupInterval   time.Duration
    MaxSize           int
    EnableAutoCleanup bool
    Store             BlacklistStore
}

Blacklist configuration.

struct

Fields ​

FieldTypeDefaultDescription
CleanupIntervaltime.Duration5mExpired entry cleanup interval (built-in store only)
MaxSizeint100000Max entries in memory store (built-in store only)
EnableAutoCleanupbooltrueAuto-cleanup of expired entries (built-in store only)
StoreBlacklistStore—Custom storage backend (when set, other fields are ignored)