Documentation
¶
Index ¶
- type AccountLockedResponse
- type AccountLockoutError
- type Config
- type Handler
- type Plugin
- func (p *Plugin) ID() string
- func (p *Plugin) Init(authInst core.Authsome) error
- func (p *Plugin) Migrate() error
- func (p *Plugin) RegisterHooks(_ *hooks.HookRegistry) error
- func (p *Plugin) RegisterRoutes(router forge.Router) error
- func (p *Plugin) RegisterServiceDecorators(_ *registry.ServiceRegistry) error
- type PluginOption
- func WithAllowUsernameLogin(allowed bool) PluginOption
- func WithDefaultConfig(cfg Config) PluginOption
- func WithLockoutDuration(duration time.Duration) PluginOption
- func WithLockoutEnabled(enabled bool) PluginOption
- func WithMaxFailedAttempts(max int) PluginOption
- func WithMaxPasswordLength(length int) PluginOption
- func WithMinPasswordLength(length int) PluginOption
- func WithPasswordExpiryDays(days int) PluginOption
- func WithPasswordExpiryEnabled(enabled bool) PluginOption
- func WithPasswordHistorySize(size int) PluginOption
- func WithPreventPasswordReuse(prevent bool) PluginOption
- func WithRequireLowercase(required bool) PluginOption
- func WithRequireNumber(required bool) PluginOption
- func WithRequireSpecialChar(required bool) PluginOption
- func WithRequireUppercase(required bool) PluginOption
- type RateLimitConfig
- type RateLimitRule
- type Service
- func (s *Service) SignInWithUsername(ctx context.Context, username, password string, remember bool, ip, ua string) (*responses.AuthResponse, error)
- func (s *Service) SignUpWithUsername(ctx context.Context, username, password, ip, ua string) error
- func (s *Service) ValidatePassword(password string) error
- type SignInRequest
- type SignInResponse
- type SignUpRequest
- type SignUpResponse
- type TwoFARequiredResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountLockedResponse ¶
type AccountLockedResponse struct {
Code string `json:"code" example:"ACCOUNT_LOCKED"`
Message string `json:"message" example:"Account locked due to too many failed login attempts"`
LockedUntil time.Time `json:"locked_until" example:"2025-11-20T12:00:00Z"`
LockedMinutes int `json:"locked_minutes" example:"15"`
}
type AccountLockoutError ¶
AccountLockoutError represents an account lockout error
func (*AccountLockoutError) Error ¶
func (e *AccountLockoutError) Error() string
type Config ¶
type Config struct {
// Password requirements (existing)
MinPasswordLength int `json:"minPasswordLength"`
MaxPasswordLength int `json:"maxPasswordLength"`
RequireUppercase bool `json:"requireUppercase"`
RequireLowercase bool `json:"requireLowercase"`
RequireNumber bool `json:"requireNumber"`
RequireSpecialChar bool `json:"requireSpecialChar"`
AllowUsernameLogin bool `json:"allowUsernameLogin"`
// Account lockout configuration
LockoutEnabled bool `json:"lockoutEnabled"`
MaxFailedAttempts int `json:"maxFailedAttempts"`
LockoutDuration time.Duration `json:"lockoutDuration"`
FailedAttemptWindow time.Duration `json:"failedAttemptWindow"`
// Password history configuration
PasswordHistorySize int `json:"passwordHistorySize"`
PreventPasswordReuse bool `json:"preventPasswordReuse"`
// Password expiry configuration
PasswordExpiryEnabled bool `json:"passwordExpiryEnabled"`
PasswordExpiryDays int `json:"passwordExpiryDays"`
PasswordExpiryWarning int `json:"passwordExpiryWarningDays"`
// Rate limiting configuration
RateLimit RateLimitConfig `json:"rateLimit"`
}
Config holds the username plugin configuration
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default username plugin configuration
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler exposes HTTP endpoints for username auth
func NewHandler ¶
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements the plugins.Plugin interface for Username auth
func NewPlugin ¶
func NewPlugin(opts ...PluginOption) *Plugin
NewPlugin creates a new username plugin instance with optional configuration
func (*Plugin) RegisterHooks ¶
func (p *Plugin) RegisterHooks(_ *hooks.HookRegistry) error
RegisterHooks placeholder
func (*Plugin) RegisterRoutes ¶
RegisterRoutes registers Username plugin routes
func (*Plugin) RegisterServiceDecorators ¶
func (p *Plugin) RegisterServiceDecorators(_ *registry.ServiceRegistry) error
type PluginOption ¶
type PluginOption func(*Plugin)
PluginOption is a functional option for configuring the username plugin
func WithAllowUsernameLogin ¶
func WithAllowUsernameLogin(allowed bool) PluginOption
WithAllowUsernameLogin sets whether username login is allowed
func WithDefaultConfig ¶
func WithDefaultConfig(cfg Config) PluginOption
WithDefaultConfig sets the default configuration for the plugin
func WithLockoutDuration ¶
func WithLockoutDuration(duration time.Duration) PluginOption
WithLockoutDuration sets the account lockout duration
func WithLockoutEnabled ¶
func WithLockoutEnabled(enabled bool) PluginOption
WithLockoutEnabled sets whether account lockout is enabled
func WithMaxFailedAttempts ¶
func WithMaxFailedAttempts(max int) PluginOption
WithMaxFailedAttempts sets the maximum failed attempts before lockout
func WithMaxPasswordLength ¶
func WithMaxPasswordLength(length int) PluginOption
WithMaxPasswordLength sets the maximum password length
func WithMinPasswordLength ¶
func WithMinPasswordLength(length int) PluginOption
WithMinPasswordLength sets the minimum password length
func WithPasswordExpiryDays ¶
func WithPasswordExpiryDays(days int) PluginOption
WithPasswordExpiryDays sets the password expiry days
func WithPasswordExpiryEnabled ¶
func WithPasswordExpiryEnabled(enabled bool) PluginOption
WithPasswordExpiryEnabled sets whether password expiry is enabled
func WithPasswordHistorySize ¶
func WithPasswordHistorySize(size int) PluginOption
WithPasswordHistorySize sets the password history size
func WithPreventPasswordReuse ¶
func WithPreventPasswordReuse(prevent bool) PluginOption
WithPreventPasswordReuse sets whether password reuse is prevented
func WithRequireLowercase ¶
func WithRequireLowercase(required bool) PluginOption
WithRequireLowercase sets whether lowercase letters are required
func WithRequireNumber ¶
func WithRequireNumber(required bool) PluginOption
WithRequireNumber sets whether numbers are required
func WithRequireSpecialChar ¶
func WithRequireSpecialChar(required bool) PluginOption
WithRequireSpecialChar sets whether special characters are required
func WithRequireUppercase ¶
func WithRequireUppercase(required bool) PluginOption
WithRequireUppercase sets whether uppercase letters are required
type RateLimitConfig ¶
type RateLimitConfig struct {
Enabled bool `json:"enabled"`
UseRedis bool `json:"useRedis"`
RedisAddr string `json:"redisAddr"`
RedisPassword string `json:"redisPassword"`
RedisDB int `json:"redisDb"`
SignUpPerIP RateLimitRule `json:"signupPerIp"`
SignInPerIP RateLimitRule `json:"signinPerIp"`
SignInPerUser RateLimitRule `json:"signinPerUser"`
}
RateLimitConfig holds rate limiting configuration
type RateLimitRule ¶
RateLimitRule defines a rate limit rule
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides username-based auth operations backed by core services
func NewService ¶
func (*Service) SignInWithUsername ¶
func (s *Service) SignInWithUsername(ctx context.Context, username, password string, remember bool, ip, ua string) (*responses.AuthResponse, error)
SignInWithUsername authenticates by username and password
func (*Service) SignUpWithUsername ¶
SignUpWithUsername creates a new user with username and password
func (*Service) ValidatePassword ¶
ValidatePassword validates password against configured requirements
type SignInRequest ¶
type SignInResponse ¶
type SignUpRequest ¶
type SignUpRequest struct {
Username string `json:"username" validate:"required" example:"johndoe"`
Password string `json:"password" validate:"required" example:"SecureP@ss123"`
}
Request types
type SignUpResponse ¶
type SignUpResponse struct {
Status string `json:"status" example:"created"`
Message string `json:"message,omitempty" example:"User created successfully"`
}
Response types