Versions in this module Expand all Collapse all v1 v1.1.0 Dec 26, 2025 v1.0.0 Dec 26, 2025 Changes in this version + const DefaultAPIKeyLength + const DefaultAPIKeyPrefix + const DefaultAPIKeyPrefixLength + const DefaultAccessTokenTTL + const DefaultRefreshTokenTTL + var ErrInvalidAPIKey = errors.New("invalid API key format") + var ErrInvalidToken = errors.New("invalid token") + var ErrSecretTooShort = errors.New("JWT secret must be at least 32 bytes") + var ErrTokenExpired = errors.New("token expired") + func ExtractAPIKeyPrefix(key string, cfg APIKeyConfig) string + func GenerateAccessToken(cfg JWTConfig, subject string) (string, error) + func GenerateAccessTokenWithClaims[T jwt.Claims](cfg JWTConfig, builder func(BaseClaims) T) (string, error) + func GenerateRefreshToken() (token, hash string, err error) + func HashToken(token string) string + func ValidateAPIKeyFormat(key string, cfg APIKeyConfig) bool + func ValidateAccessTokenAs(cfg JWTConfig, tokenString string, claims jwt.Claims) error + type APIKeyConfig struct + Prefix string + PrefixLength int + RandomLength int + type APIKeyWithSecret struct + Hash string + ID string + Prefix string + Secret string + func GenerateAPIKey(cfg APIKeyConfig) (*APIKeyWithSecret, error) + type BaseClaims struct + func ValidateAccessToken(cfg JWTConfig, tokenString string) (*BaseClaims, error) + type JWTConfig struct + AccessTokenTTL time.Duration + Issuer string + RefreshTokenTTL time.Duration + Secret []byte + type TokenPair struct + AccessToken string + ExpiresIn int64 + RefreshToken string + func GenerateTokenPair(cfg JWTConfig, subject string) (*TokenPair, string, error) + func GenerateTokenPairWithClaims[T jwt.Claims](cfg JWTConfig, builder func(BaseClaims) T) (*TokenPair, string, error)