Documentation
¶
Overview ¶
Deprecated placeholder implementation removed. This file intentionally left minimal to avoid duplicate JWT types.
Index ¶
- Variables
- func ListProviders() []string
- func RegisterProvider(name string, factory ProviderFactory) error
- type AuthProvider
- type Authenticator
- func (a *Authenticator) AddProvider(provider AuthProvider)
- func (a *Authenticator) Authenticate(ctx context.Context, username, password string) (*models.User, error)
- func (a *Authenticator) GetProviders() []string
- func (a *Authenticator) GetUser(ctx context.Context, identifier string) (*models.User, error)
- func (a *Authenticator) ValidateToken(ctx context.Context, token string) (*models.User, error)
- type Claims
- type DatabaseAuthProvider
- func (p *DatabaseAuthProvider) Authenticate(ctx context.Context, username, password string) (*models.User, error)
- func (p *DatabaseAuthProvider) GetUser(ctx context.Context, identifier string) (*models.User, error)
- func (p *DatabaseAuthProvider) Name() string
- func (p *DatabaseAuthProvider) Priority() int
- func (p *DatabaseAuthProvider) ValidateToken(ctx context.Context, token string) (*models.User, error)
- type JWTManager
- func (m *JWTManager) GenerateRefreshToken(userID uint, email string) (string, error)
- func (m *JWTManager) GenerateToken(userID uint, email, role string, tenantID uint) (string, error)
- func (m *JWTManager) TokenDuration() time.Duration
- func (m *JWTManager) ValidateRefreshToken(tokenString string) (*jwt.RegisteredClaims, error)
- func (m *JWTManager) ValidateToken(tokenString string) (*Claims, error)
- type LDAPAuthProvider
- func (p *LDAPAuthProvider) Authenticate(ctx context.Context, username, password string) (*models.User, error)
- func (p *LDAPAuthProvider) GetUser(ctx context.Context, identifier string) (*models.User, error)
- func (p *LDAPAuthProvider) Name() string
- func (p *LDAPAuthProvider) Priority() int
- func (p *LDAPAuthProvider) ValidateToken(ctx context.Context, token string) (*models.User, error)
- type LDAPConfig
- type PasswordHashType
- type PasswordHasher
- type Permission
- type ProviderDependencies
- type ProviderFactory
- type RBAC
- func (r *RBAC) CanAccessAdminPanel(role string) bool
- func (r *RBAC) CanAccessTicket(role string, ticketOwnerID, userID uint) bool
- func (r *RBAC) CanAssignTicket(role string) bool
- func (r *RBAC) CanCloseTicket(role string) bool
- func (r *RBAC) CanModifyUser(actorRole string, targetUserRole string) bool
- func (r *RBAC) CanViewReports(role string) bool
- func (r *RBAC) GetRolePermissions(role string) []Permission
- func (r *RBAC) HasPermission(role string, permission Permission) bool
- type StaticAuthProvider
- func (p *StaticAuthProvider) Authenticate(ctx context.Context, username, password string) (*models.User, error)
- func (p *StaticAuthProvider) GetUser(ctx context.Context, identifier string) (*models.User, error)
- func (p *StaticAuthProvider) Name() string
- func (p *StaticAuthProvider) Priority() int
- func (p *StaticAuthProvider) ValidateToken(ctx context.Context, token string) (*models.User, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidCredentials = errors.New("invalid credentials") ErrUserNotFound = errors.New("user not found") ErrUserDisabled = errors.New("user account is disabled") ErrAuthBackendFailed = errors.New("authentication backend failed") )
Common errors
var ( ErrInvalidToken = errors.New("invalid token") ErrExpiredToken = errors.New("token has expired") )
Functions ¶
func RegisterProvider ¶
func RegisterProvider(name string, factory ProviderFactory) error
RegisterProvider registers a provider factory by name (lowercase unique key).
Types ¶
type AuthProvider ¶
type AuthProvider interface {
// Authenticate attempts to authenticate a user with the given credentials
// Returns the authenticated user and nil error on success
Authenticate(ctx context.Context, username, password string) (*models.User, error)
// GetUser retrieves user details by username/email
GetUser(ctx context.Context, identifier string) (*models.User, error)
// ValidateToken validates an existing session/token
ValidateToken(ctx context.Context, token string) (*models.User, error)
// Name returns the name of this auth provider
Name() string
// Priority returns the priority of this provider (lower = higher priority)
Priority() int
}
AuthProvider defines the interface for authentication providers
func CreateProvider ¶
func CreateProvider(name string, deps ProviderDependencies) (AuthProvider, error)
CreateProvider instantiates a provider by name.
type Authenticator ¶
type Authenticator struct {
// contains filtered or unexported fields
}
Authenticator manages multiple authentication providers
func NewAuthenticator ¶
func NewAuthenticator(providers ...AuthProvider) *Authenticator
NewAuthenticator creates a new authenticator with the given providers
func (*Authenticator) AddProvider ¶
func (a *Authenticator) AddProvider(provider AuthProvider)
AddProvider adds a new authentication provider
func (*Authenticator) Authenticate ¶
func (a *Authenticator) Authenticate(ctx context.Context, username, password string) (*models.User, error)
Authenticate attempts to authenticate using all configured providers
func (*Authenticator) GetProviders ¶
func (a *Authenticator) GetProviders() []string
GetProviders returns the list of configured providers
func (*Authenticator) ValidateToken ¶
ValidateToken validates a token using the primary provider
type DatabaseAuthProvider ¶
type DatabaseAuthProvider struct {
// contains filtered or unexported fields
}
DatabaseAuthProvider provides authentication against the database
func NewDatabaseAuthProvider ¶
func NewDatabaseAuthProvider(db *sql.DB) *DatabaseAuthProvider
NewDatabaseAuthProvider creates a new database authentication provider
func (*DatabaseAuthProvider) Authenticate ¶
func (p *DatabaseAuthProvider) Authenticate(ctx context.Context, username, password string) (*models.User, error)
Authenticate authenticates a user against the database
func (*DatabaseAuthProvider) GetUser ¶
func (p *DatabaseAuthProvider) GetUser(ctx context.Context, identifier string) (*models.User, error)
GetUser retrieves user details by username or email
func (*DatabaseAuthProvider) Name ¶
func (p *DatabaseAuthProvider) Name() string
Name returns the name of this auth provider
func (*DatabaseAuthProvider) Priority ¶
func (p *DatabaseAuthProvider) Priority() int
Priority returns the priority of this provider
func (*DatabaseAuthProvider) ValidateToken ¶
func (p *DatabaseAuthProvider) ValidateToken(ctx context.Context, token string) (*models.User, error)
ValidateToken validates a session token (for future implementation)
type JWTManager ¶
type JWTManager struct {
// contains filtered or unexported fields
}
func NewJWTManager ¶
func NewJWTManager(secretKey string, tokenDuration time.Duration) *JWTManager
func (*JWTManager) GenerateRefreshToken ¶
func (m *JWTManager) GenerateRefreshToken(userID uint, email string) (string, error)
func (*JWTManager) GenerateToken ¶
func (*JWTManager) TokenDuration ¶
func (m *JWTManager) TokenDuration() time.Duration
func (*JWTManager) ValidateRefreshToken ¶
func (m *JWTManager) ValidateRefreshToken(tokenString string) (*jwt.RegisteredClaims, error)
func (*JWTManager) ValidateToken ¶
func (m *JWTManager) ValidateToken(tokenString string) (*Claims, error)
type LDAPAuthProvider ¶
type LDAPAuthProvider struct {
// contains filtered or unexported fields
}
LDAPAuthProvider provides authentication against LDAP
func NewLDAPAuthProvider ¶
func NewLDAPAuthProvider(config *LDAPConfig) *LDAPAuthProvider
NewLDAPAuthProvider creates a new LDAP authentication provider
func (*LDAPAuthProvider) Authenticate ¶
func (p *LDAPAuthProvider) Authenticate(ctx context.Context, username, password string) (*models.User, error)
Authenticate authenticates a user against LDAP
func (*LDAPAuthProvider) Name ¶
func (p *LDAPAuthProvider) Name() string
Name returns the name of this auth provider
func (*LDAPAuthProvider) Priority ¶
func (p *LDAPAuthProvider) Priority() int
Priority returns the priority of this provider
func (*LDAPAuthProvider) ValidateToken ¶
ValidateToken validates a session token
type LDAPConfig ¶
type LDAPConfig struct {
Server string
Port int
BaseDN string
BindDN string
BindPass string
UserFilter string
TLS bool
}
LDAPConfig holds LDAP server configuration
type PasswordHashType ¶
type PasswordHashType string
PasswordHashType represents the hashing algorithm to use
const ( HashTypeBcrypt PasswordHashType = "bcrypt" HashTypeSHA256 PasswordHashType = "sha256" HashTypeSHA512 PasswordHashType = "sha512" HashTypeMD5 PasswordHashType = "md5" HashTypeAuto PasswordHashType = "auto" // Auto-detect from hash format )
type PasswordHasher ¶
type PasswordHasher struct {
// contains filtered or unexported fields
}
PasswordHasher handles password hashing and verification
func NewPasswordHasher ¶
func NewPasswordHasher() *PasswordHasher
NewPasswordHasher creates a new password hasher
func (*PasswordHasher) HashPassword ¶
func (h *PasswordHasher) HashPassword(password string) (string, error)
HashPassword hashes a password using the configured algorithm
func (*PasswordHasher) MigratePasswordHash ¶
func (h *PasswordHasher) MigratePasswordHash(password, oldHash string, targetType PasswordHashType) (string, error)
MigratePasswordHash optionally upgrades password hash on successful login
func (*PasswordHasher) VerifyPassword ¶
func (h *PasswordHasher) VerifyPassword(password, hash string) bool
VerifyPassword checks if a password matches the hash
type Permission ¶
type Permission string
const ( // Ticket permissions PermissionTicketCreate Permission = "ticket:create" PermissionTicketRead Permission = "ticket:read" PermissionTicketUpdate Permission = "ticket:update" PermissionTicketDelete Permission = "ticket:delete" PermissionTicketAssign Permission = "ticket:assign" PermissionTicketClose Permission = "ticket:close" // User permissions PermissionUserCreate Permission = "user:create" PermissionUserRead Permission = "user:read" PermissionUserUpdate Permission = "user:update" PermissionUserDelete Permission = "user:delete" // Admin permissions PermissionAdminAccess Permission = "admin:access" PermissionSystemConfig Permission = "system:config" // Report permissions PermissionReportView Permission = "report:view" PermissionReportCreate Permission = "report:create" // Customer permissions PermissionOwnTicketRead Permission = "own:ticket:read" PermissionOwnTicketCreate Permission = "own:ticket:create" )
type ProviderDependencies ¶
ProviderDependencies bundles common resources providers may need.
type ProviderFactory ¶
type ProviderFactory func(deps ProviderDependencies) (AuthProvider, error)
ProviderFactory builds an AuthProvider given dependencies.
type RBAC ¶
type RBAC struct {
// contains filtered or unexported fields
}
func (*RBAC) CanAccessAdminPanel ¶
func (*RBAC) CanAccessTicket ¶
func (*RBAC) CanAssignTicket ¶
func (*RBAC) CanCloseTicket ¶
func (*RBAC) CanModifyUser ¶
func (*RBAC) CanViewReports ¶
func (*RBAC) GetRolePermissions ¶
func (r *RBAC) GetRolePermissions(role string) []Permission
func (*RBAC) HasPermission ¶
func (r *RBAC) HasPermission(role string, permission Permission) bool
type StaticAuthProvider ¶
type StaticAuthProvider struct {
// contains filtered or unexported fields
}
StaticAuthProvider offers simple in-memory users for demos/tests.
func NewStaticAuthProvider ¶
func NewStaticAuthProvider(specs []string) *StaticAuthProvider
static user spec env format: user:password:Role(Agent|Customer|Admin) Multiple separated by commas.
func (*StaticAuthProvider) Authenticate ¶
func (*StaticAuthProvider) Name ¶
func (p *StaticAuthProvider) Name() string
func (*StaticAuthProvider) Priority ¶
func (p *StaticAuthProvider) Priority() int