Skip to content

Interfaces ​

TokenManager ​

go
type TokenManager interface {
    Create(claims CustomClaims) (string, error)
    Validate(tokenString string) (Claims, bool, error)
    CreateRefresh(claims CustomClaims) (string, error)
    Refresh(refreshTokenString string) (string, error)
    ValidateInto(tokenString string, claims CustomClaims) (CustomClaims, bool, error)
    RefreshInto(refreshTokenString string, claims CustomClaims) (string, error)
    Revoke(tokenString string) error
    IsRevoked(tokenString string) (bool, error)
    ParseUnverified(tokenString string, claims any) error
    Close() error
    IsClosed() bool
}

Core JWT token operations interface. All implementations must be concurrency-safe. The default implementation is *Processor.

Compatibility Note

The interface deliberately still carries Validate / ValidateInto — although both are deprecated on *Processor in favor of Parse / ParseInto — because adding or swapping methods here would break third-party TokenManager implementations.

Methods are grouped by responsibility:

  • Token Creation: Create, CreateRefresh
  • Validation & Refresh: Validate, ValidateInto, Refresh, RefreshInto
  • General Operations: Revoke, IsRevoked, ParseUnverified, Close, IsClosed
interface

Methods ​

MethodSignatureDescription
CreateCreate(claims CustomClaims) (string, error)Create access token
ValidateValidate(tokenString string) (Claims, bool, error)Validate token (deprecated on *Processor; prefer Parse)
CreateRefreshCreateRefresh(claims CustomClaims) (string, error)Create refresh token
RefreshRefresh(refreshTokenString string) (string, error)Refresh token
ValidateIntoValidateInto(tokenString string, claims CustomClaims) (CustomClaims, bool, error)Validate into custom Claims (deprecated on *Processor; prefer ParseInto)
RefreshIntoRefreshInto(refreshTokenString string, claims CustomClaims) (string, error)Refresh into custom Claims
RevokeRevoke(tokenString string) errorRevoke token
IsRevokedIsRevoked(tokenString string) (bool, error)Check if revoked
ParseUnverifiedParseUnverified(tokenString string, claims any) errorParse without verification
CloseClose() errorRelease resources
IsClosedIsClosed() boolWhether closed

Implementations ​

TypeDescription
*ProcessorDefault implementation

CustomClaims ​

go
type CustomClaims interface {
    GetRegisteredClaims() *RegisteredClaims
    Validate() error
}

Custom Claims interface. Used with Create, ParseInto, RefreshInto and other methods.

interface

Validation Contract ​

The Processor applies different validation paths for *Claims versus other types:

TypeValidation Behavior
*ClaimsDeep validation: all fields (length limits, injection patterns, control characters)
Other typesCalls Validate() + registered claims string sanitization (Issuer, Subject, ID, TokenType, Audience)

WARNING

For non-*Claims types, custom struct fields are not deep-validated. Implementers must validate all business fields in the Validate() method.

Methods ​

MethodSignatureDescription
GetRegisteredClaimsGetRegisteredClaims() *RegisteredClaimsReturns standard JWT fields
ValidateValidate() errorCustom validation logic

Implementations ​

TypeDescription
*ClaimsBuilt-in Claims implementation

BlacklistStore ​

go
type BlacklistStore interface {
    Add(tokenID string, expiresAt time.Time) error
    Contains(tokenID string) (bool, error)
    Close() error
}

Blacklist storage backend interface.

interface

Methods ​

MethodSignatureDescription
AddAdd(tokenID string, expiresAt time.Time) errorAdd to blacklist
ContainsContains(tokenID string) (bool, error)Check if in blacklist
CloseClose() errorRelease resources

RateLimitProvider ​

go
type RateLimitProvider interface {
    Allow(key string) bool
    Reset(key string)
    Close()
}

Rate limiting interface. The Processor calls Allow(key) for a single check during token creation.

About AllowN

The interface itself only defines Allow for single-request checks. The batch method AllowN(key string, n int) bool is an extension method on the concrete type *RateLimiter and is not part of this interface.

interface

Methods ​

MethodSignatureDescription
AllowAllow(key string) boolCheck if single request is allowed
ResetReset(key string)Reset rate limit state for key
CloseClose()Release resources

Implementations ​

TypeDescription
*RateLimiterBuilt-in token bucket implementation

ClockProvider ​

go
type ClockProvider interface {
    Now() time.Time
}

Clock interface for time injection (testing scenarios).

interface

Implementations ​

TypeDescription
SystemClockSystem clock
FixedClockFixed time clock

RateLimitKeyer ​

go
type RateLimitKeyer interface {
    RateLimitKey() string
}

Optional interface. Custom Claims can implement this to provide a rate limit key. Key lookup priority: Subject → *Claims.UserID → RateLimitKey(); when the resolved key is empty, rate limiting is skipped.

interface

Methods ​

MethodSignatureDescription
RateLimitKeyRateLimitKey() stringReturns the rate limit key (used when both Subject and *Claims.UserID are empty)