Documentation
¶
Index ¶
- func Chain(middlewares ...func(http.Handler) http.Handler) func(http.Handler) http.Handler
- func Compose(handlers ...func(http.HandlerFunc) http.HandlerFunc) func(http.HandlerFunc) http.HandlerFunc
- func GetClaimsFromContext(ctx context.Context) (jwt.MapClaims, bool)
- func GetUserIDFromContext(ctx context.Context) (string, bool)
- func IsConfigurationError(err error) bool
- func IsValidationError(err error) bool
- type CachedToken
- type ClaimsValidator
- type ConfigurationError
- type ContextKey
- type JWTConfig
- type JWTValidator
- type Option
- type PassthroughValidator
- type TokenExtractor
- type ValidationError
- type ValidationResult
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compose ¶ added in v0.0.3
func Compose(handlers ...func(http.HandlerFunc) http.HandlerFunc) func(http.HandlerFunc) http.HandlerFunc
Compose combines multiple handler functions
func GetClaimsFromContext ¶
GetClaimsFromContext extracts JWT claims from request context
func GetUserIDFromContext ¶
GetUserIDFromContext extracts user ID from JWT claims in context
func IsConfigurationError ¶ added in v0.0.3
IsConfigurationError checks if an error is a ConfigurationError
func IsValidationError ¶ added in v0.0.3
IsValidationError checks if an error is a ValidationError
Types ¶
type CachedToken ¶
CachedToken represents a cached validated token
type ClaimsValidator ¶ added in v0.0.3
ClaimsValidator interface for flexible claims validation
type ConfigurationError ¶ added in v0.0.3
ConfigurationError represents configuration errors
func (*ConfigurationError) Error ¶ added in v0.0.3
func (e *ConfigurationError) Error() string
type ContextKey ¶
type ContextKey string
ContextKey is a type-safe key for context values
const ( // JWTClaimsKey is the context key for JWT claims JWTClaimsKey ContextKey = "jwt_claims" )
type JWTConfig ¶
type JWTConfig struct {
ClientID string
JWKSURL string
Scope string
AllowedAlgs []string
CacheTTL time.Duration
RefreshInterval time.Duration
}
JWTConfig holds configuration for JWT validation
func DefaultJWTConfig ¶
func DefaultJWTConfig() *JWTConfig
DefaultJWTConfig provides secure defaults
type JWTValidator ¶
type JWTValidator struct {
// contains filtered or unexported fields
}
JWTValidator provides hardened JWT validation with comprehensive security checks
func NewJWTValidator ¶
func NewJWTValidator(config *JWTConfig) (*JWTValidator, error)
NewJWTValidator creates a new hardened JWT validator
func (*JWTValidator) Middleware ¶
func (v *JWTValidator) Middleware(next http.Handler) http.Handler
Middleware returns a middleware function that validates JWT tokens
func (*JWTValidator) Protect ¶
func (v *JWTValidator) Protect(next http.HandlerFunc) http.HandlerFunc
Protect wraps a handler function with JWT validation
func (*JWTValidator) RevokeToken ¶
func (v *JWTValidator) RevokeToken(tokenString string)
RevokeToken marks a token as revoked
func (*JWTValidator) ValidateRequest ¶
func (v *JWTValidator) ValidateRequest(r *http.Request) ValidationResult
ValidateRequest performs comprehensive JWT validation
type Option ¶ added in v0.0.3
type Option func(*JWTValidator)
Option is a functional option for configuring JWT validation
func WithAllowedAlgs ¶ added in v0.0.3
WithAllowedAlgs sets the allowed signing algorithms
func WithCacheTTL ¶ added in v0.0.3
WithCacheTTL sets the token cache TTL
func WithClaimsValidator ¶ added in v0.0.3
func WithClaimsValidator(validator ClaimsValidator) Option
WithClaimsValidator sets a custom claims validator
func WithTokenExtractor ¶ added in v0.0.3
func WithTokenExtractor(extractor TokenExtractor) Option
WithTokenExtractor sets a custom token extractor
type PassthroughValidator ¶
type PassthroughValidator struct{}
PassthroughValidator for testing/development
func NewPassthroughValidator ¶
func NewPassthroughValidator() *PassthroughValidator
func (*PassthroughValidator) Middleware ¶
func (v *PassthroughValidator) Middleware(next http.Handler) http.Handler
func (*PassthroughValidator) Protect ¶
func (v *PassthroughValidator) Protect(next http.HandlerFunc) http.HandlerFunc
type TokenExtractor ¶ added in v0.0.3
TokenExtractor interface for flexible token extraction
type ValidationError ¶ added in v0.0.3
ValidationError represents JWT validation errors
func (*ValidationError) Error ¶ added in v0.0.3
func (e *ValidationError) Error() string
Error methods for better error handling
type ValidationResult ¶
ValidationResult provides detailed validation information
type Validator ¶ added in v0.0.3
type Validator interface {
Middleware(next http.Handler) http.Handler
Protect(next http.HandlerFunc) http.HandlerFunc
ValidateRequest(r *http.Request) ValidationResult
}
Validator interface defines the contract for JWT validation