Documentation
¶
Index ¶
- func GetRoleFromContext(c ctx.Ctx) (string, bool)
- func GetUserFromContext(c ctx.Ctx) (*jwt.Claims, bool)
- func GetUserIDFromContext(c ctx.Ctx) (string, bool)
- func HasAnyRole(c ctx.Ctx, roles ...string) bool
- func HasRole(c ctx.Ctx, role string) bool
- func IsAuthenticated(c ctx.Ctx) bool
- type AccountRepository
- type Handlers
- type LoginRequest
- type LoginResponse
- type Middleware
- type PasswordResetRequest
- type PasswordResetRequestRequest
- type PasswordResetRequestResponse
- type PasswordResetResponse
- type RefreshRequest
- type RefreshResponse
- type UserInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRoleFromContext ¶
GetRoleFromContext extracts user role from context
func GetUserFromContext ¶
GetUserFromContext extracts user claims from context
func GetUserIDFromContext ¶
GetUserIDFromContext extracts user ID from context
func HasAnyRole ¶
HasAnyRole checks if the current user has any of the specified roles
func IsAuthenticated ¶
IsAuthenticated checks if the current request is authenticated
Types ¶
type AccountRepository ¶
type AccountRepository interface {
GetByEmail(email string) (*adapter.Account, error)
GetByUsername(username string) (*adapter.Account, error)
Get(id string) (*adapter.Account, error)
Update(a *adapter.Account) error
}
AccountRepository defines the interface for account operations
type Handlers ¶
type Handlers struct {
// contains filtered or unexported fields
}
Handlers provides authentication HTTP handlers
func NewHandlers ¶
func NewHandlers( repo AccountRepository, jwtService *jwt.Service, refreshTokenRepo adapter.RefreshTokenRepository, resetTokenRepo adapter.PasswordResetTokenRepository, ) *Handlers
NewHandlers creates new authentication handlers
func (*Handlers) RequestPasswordReset ¶
RequestPasswordReset handles password reset requests
func (*Handlers) ResetPassword ¶
ResetPassword handles password reset using a valid token
type LoginRequest ¶
type LoginRequest struct {
Email string `json:"email,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password" validate:"required"`
}
LoginRequest represents a login request payload
type LoginResponse ¶
type LoginResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresAt time.Time `json:"expires_at"`
User UserInfo `json:"user"`
}
LoginResponse represents a login response
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware provides authentication middleware
func NewMiddleware ¶
func NewMiddleware(jwtService *jwt.Service) *Middleware
NewMiddleware creates a new authentication middleware
func (*Middleware) OptionalAuth ¶
func (m *Middleware) OptionalAuth() ctx.Handler
OptionalAuth is a middleware that extracts auth but doesn't require it
func (*Middleware) RequireAuth ¶
func (m *Middleware) RequireAuth() ctx.Handler
RequireAuth is a middleware that requires authentication
func (*Middleware) RequireRole ¶
func (m *Middleware) RequireRole(roles ...string) ctx.Handler
RequireRole is a middleware that requires a specific role
type PasswordResetRequest ¶
type PasswordResetRequest struct {
Token string `json:"token" validate:"required"`
NewPassword string `json:"new_password" validate:"required,min=8"`
}
PasswordResetRequest represents a password reset payload
type PasswordResetRequestRequest ¶
type PasswordResetRequestRequest struct {
Email string `json:"email" validate:"required,email"`
}
PasswordResetRequestRequest represents a password reset request payload
type PasswordResetRequestResponse ¶
type PasswordResetRequestResponse struct {
Message string `json:"message"`
}
PasswordResetRequestResponse represents the response to a password reset request
type PasswordResetResponse ¶
type PasswordResetResponse struct {
Message string `json:"message"`
}
PasswordResetResponse represents the response to a password reset
type RefreshRequest ¶
type RefreshRequest struct {
RefreshToken string `json:"refresh_token" validate:"required"`
}
RefreshRequest represents a token refresh request