Documentation
¶
Index ¶
- func AuditLoginFailed(c *gin.Context, username, reason string)
- func AuditLoginSuccess(c *gin.Context, userID uint, rememberMe bool)
- func AuditLogout(c *gin.Context, userID uint)
- func AuditRateLimitExceeded(c *gin.Context, endpoint string)
- func AuditRefreshFailed(c *gin.Context, reason string)
- func AuditRefreshSuccess(c *gin.Context, userID uint)
- func CleanupExpiredTokens(ctx context.Context) (int64, error)
- func DeleteRefreshToken(ctx context.Context, tokenString string) error
- func ExtractToken(c *gin.Context) string
- func ExtractTokenID(c *gin.Context) (uint, error)
- func GenerateToken(userID uint) (string, error)
- func HashPassword(password string) (string, error)
- func JwtAuthAdminProcessor() gin.HandlerFunc
- func JwtAuthProcessor() gin.HandlerFunc
- func RefreshRateLimiter(requestsPerMinute, burstSize int) gin.HandlerFunc
- func RefreshTokenHandler(c *gin.Context)
- func TokenValid(c *gin.Context) error
- func UpdateLastUsed(ctx context.Context, tokenID uint) error
- func VerifyPassword(password, hashedPassword string) error
- type AuditEvent
- type AuditEventType
- type IPRateLimiter
- type RefreshResponse
- type RefreshToken
- type RefreshTokenInput
- type TokenPairResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuditLoginFailed ¶ added in v0.16.0
AuditLoginFailed logs a failed login attempt
func AuditLoginSuccess ¶ added in v0.16.0
AuditLoginSuccess logs a successful login attempt
func AuditLogout ¶ added in v0.16.0
AuditLogout logs a logout event
func AuditRateLimitExceeded ¶ added in v0.16.0
AuditRateLimitExceeded logs a rate limit exceeded event
func AuditRefreshFailed ¶ added in v0.16.0
AuditRefreshFailed logs a failed token refresh attempt
func AuditRefreshSuccess ¶ added in v0.16.0
AuditRefreshSuccess logs a successful token refresh
func CleanupExpiredTokens ¶ added in v0.16.0
CleanupExpiredTokens deletes expired refresh tokens
func DeleteRefreshToken ¶ added in v0.16.0
DeleteRefreshToken deletes a refresh token (revocation)
func ExtractToken ¶
ExtractToken extracts token from header or query (existing function, moved here)
func ExtractTokenID ¶
ExtractTokenID extracts user ID from token (existing function, moved here)
func GenerateToken ¶
GenerateToken generates a JWT access token (existing function, moved here)
func HashPassword ¶
HashPassword hashes a password using bcrypt
func JwtAuthAdminProcessor ¶
func JwtAuthAdminProcessor() gin.HandlerFunc
JwtAuthAdminProcessor validates JWT and checks admin role (existing function, moved here)
func JwtAuthProcessor ¶
func JwtAuthProcessor() gin.HandlerFunc
JwtAuthProcessor validates JWT tokens (existing function, moved here)
func RefreshRateLimiter ¶ added in v0.16.0
func RefreshRateLimiter(requestsPerMinute, burstSize int) gin.HandlerFunc
RefreshRateLimiter creates a rate limiting middleware for /auth/refresh endpoint
func RefreshTokenHandler ¶ added in v0.16.0
RefreshTokenHandler handles POST /auth/refresh @Summary Refresh access token @Description Exchange a valid refresh token for a new access token @Tags Authentication @Accept json @Produce json @Param refresh_token body RefreshTokenInput true "Refresh Token" @Success 200 {object} RefreshResponse @Failure 400 {object} apitypes.ErrorResponse "Invalid input" @Failure 401 {object} apitypes.ErrorResponse "Invalid or expired refresh token" @Failure 500 {object} apitypes.ErrorResponse "Internal server error" @Router /auth/refresh [post]
func TokenValid ¶
TokenValid validates a JWT token (existing function, moved here)
func UpdateLastUsed ¶ added in v0.16.0
UpdateLastUsed updates the last_used_at timestamp
func VerifyPassword ¶
VerifyPassword verifies a password against a bcrypt hash
Types ¶
type AuditEvent ¶ added in v0.16.0
type AuditEvent struct {
Timestamp time.Time `json:"timestamp"`
EventType AuditEventType `json:"event_type"`
UserID *uint `json:"user_id,omitempty"`
Username string `json:"username,omitempty"`
IP string `json:"ip"`
UserAgent string `json:"user_agent,omitempty"`
Message string `json:"message"`
RememberMe bool `json:"remember_me,omitempty"`
}
AuditEvent represents a security audit event
type AuditEventType ¶ added in v0.16.0
type AuditEventType string
AuditEventType represents the type of audit event
const ( // Authentication events EventLoginSuccess AuditEventType = "login_success" EventLoginFailed AuditEventType = "login_failed" EventRefreshSuccess AuditEventType = "refresh_success" EventRefreshFailed AuditEventType = "refresh_failed" EventLogout AuditEventType = "logout" EventRateLimitExceeded AuditEventType = "rate_limit_exceeded" )
type IPRateLimiter ¶ added in v0.16.0
type IPRateLimiter struct {
// contains filtered or unexported fields
}
IPRateLimiter manages rate limiters per IP address
func NewIPRateLimiter ¶ added in v0.16.0
func NewIPRateLimiter(requestsPerMinute, burstSize int) *IPRateLimiter
NewIPRateLimiter creates a new IP-based rate limiter
func (*IPRateLimiter) GetLimiter ¶ added in v0.16.0
func (rl *IPRateLimiter) GetLimiter(ip string) *rate.Limiter
GetLimiter returns the rate limiter for an IP, creating if needed
type RefreshResponse ¶ added in v0.16.0
type RefreshResponse struct {
AccessToken string `json:"access_token"`
ExpiresIn int64 `json:"expires_in"`
}
RefreshResponse represents the response from refresh endpoint
type RefreshToken ¶ added in v0.16.0
type RefreshToken struct {
ID uint `json:"id"`
Token string `json:"token"`
AccountID uint `json:"account_id"`
ExpiresAt time.Time `json:"expires_at"`
CreatedAt time.Time `json:"created_at"`
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
Revoked bool `json:"revoked"`
}
RefreshToken represents a refresh token in the database
func CreateRefreshToken ¶ added in v0.16.0
func CreateRefreshToken(ctx context.Context, accountID uint, rememberMe bool) (*RefreshToken, error)
CreateRefreshToken creates a new refresh token for a user
func GetRefreshToken ¶ added in v0.16.0
func GetRefreshToken(ctx context.Context, tokenString string) (*RefreshToken, error)
GetRefreshToken retrieves a refresh token by token string
type RefreshTokenInput ¶ added in v0.16.0
type RefreshTokenInput struct {
Token string `json:"refresh_token" binding:"required"`
}
RefreshTokenInput represents the input for refresh token endpoint
type TokenPairResponse ¶ added in v0.16.0
type TokenPairResponse struct {
Token string `json:"token"` // Backward compatibility - same as AccessToken
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
AccessExpiresIn int64 `json:"access_expires_in"`
RefreshExpiresIn int64 `json:"refresh_expires_in"`
}
TokenPairResponse represents access + refresh token pair
func GenerateTokenPair ¶ added in v0.16.0
func GenerateTokenPair(ctx context.Context, accountID uint, rememberMe bool) (*TokenPairResponse, error)
GenerateTokenPair generates both access and refresh tokens (NEW)