auth

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JWTMiddleware

func JWTMiddleware(config *JWTConfig) gin.HandlerFunc

JWTMiddleware crea middleware de autenticación JWT mejorado

func RequireRole added in v1.0.0

func RequireRole(role string) gin.HandlerFunc

RequireRole middleware que requiere un rol específico

Types

type Claims added in v1.0.0

type Claims struct {
	UserID      string   `json:"sub"`
	TenantID    string   `json:"tenant_id"`
	Role        string   `json:"role"`
	Permissions []string `json:"permissions,omitempty"`
	Email       string   `json:"email"`
	SessionID   string   `json:"session_id,omitempty"`
	TokenType   string   `json:"token_type"`
	jwt.RegisteredClaims
}

Claims representa los claims del JWT token

func GetClaimsFromContext added in v1.0.0

func GetClaimsFromContext(c *gin.Context) (*Claims, error)

GetClaimsFromContext extrae los claims del contexto de Gin

type JWTConfig

type JWTConfig struct {
	// Token configuration
	SecretKey       string
	TokenLookup     string // "header:Authorization,query:token,cookie:jwt"
	TokenHeadName   string // "Bearer"
	TokenExpiration time.Duration

	// Validation options
	SkipPaths      []string
	RequiredClaims []string
	AllowedIssuers []string

	// Cache configuration for token blacklist/validation
	CacheClient cache.CacheInterface
	CachePrefix string
	CacheTTL    time.Duration

	// Security options
	EnableBlacklist  bool
	MaxTokensPerUser int

	// Custom functions
	SkipperFunc  func(*gin.Context) bool
	ClaimsFunc   func(*gin.Context, *Claims)
	ErrorHandler func(*gin.Context, error)
}

JWTConfig configuración del middleware JWT mejorada

func DefaultJWTConfig

func DefaultJWTConfig(secretKey string) *JWTConfig

DefaultJWTConfig retorna configuración por defecto mejorada

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL