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
    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
SecretKeystringHMAC key (at least 32 bytes)
SigningKeyanyAsymmetric algorithm private key (*rsa.PrivateKey or *ecdsa.PrivateKey)
VerificationKeyanyAsymmetric 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
ExpectedAudiencestringExpected audience (optional)
RequireExpirationboolfalseWhen true, rejects tokens lacking an exp claim during validation (returns ErrExpirationRequired)
ClockSkewtime.Duration0Clock skew leeway applied to exp/nbf during validation (tolerates clock drift between issuer and validator); negative values are rejected by Validate()
BlacklistBlacklistConfigBlacklist configuration
EnableRateLimitboolfalseEnable rate limiting
RateLimitRateint100Max requests per window
RateLimitWindowtime.Duration1mRate limit window
RateLimiterRateLimitProviderCustom 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)
StoreBlacklistStoreCustom storage backend (when set, other fields are ignored)