Documentation
¶
Index ¶
- Constants
- Variables
- func AuthMiddleware(service *Service) gin.HandlerFunc
- func InitializeGoth()
- func OptionalAuthMiddleware(service *Service) gin.HandlerFunc
- type AuthResponse
- type Handler
- func (h *Handler) BeginOAuth(c *gin.Context)
- func (h *Handler) CallbackOAuth(c *gin.Context)
- func (h *Handler) GetCurrentUser(c *gin.Context)
- func (h *Handler) GetUserProfile(c *gin.Context)
- func (h *Handler) LoginWithEmail(c *gin.Context)
- func (h *Handler) Logout(c *gin.Context)
- func (h *Handler) RegisterWithEmail(c *gin.Context)
- func (h *Handler) ResendVerificationEmail(c *gin.Context)
- func (h *Handler) UpdatePassword(c *gin.Context)
- func (h *Handler) UpdateProfile(c *gin.Context)
- func (h *Handler) VerifyEmail(c *gin.Context)
- type LoginRequest
- type RegisterRequest
- type ResendVerificationRequest
- type Service
- func (s *Service) CleanupExpiredSessions() error
- func (s *Service) CreateOrUpdateOAuthUser(email, provider, providerID, avatarURL, name, username string) (*User, error)
- func (s *Service) CreateSession(userID uuid.UUID) (*Session, error)
- func (s *Service) DeleteSession(token string) error
- func (s *Service) GetUserByID(userID uuid.UUID) (*User, error)
- func (s *Service) LoginWithEmail(email, password string) (*User, *Session, error)
- func (s *Service) RegisterWithEmail(email, password string) (*User, error)
- func (s *Service) ResendVerificationEmail(email string) error
- func (s *Service) UpdateUserPassword(userID uuid.UUID, newPassword string) error
- func (s *Service) UpdateUserProfile(userID uuid.UUID, username, name, avatarURL *string) (*User, error)
- func (s *Service) ValidateSession(token string) (*User, *Session, error)
- func (s *Service) VerifyEmail(token string) (*User, error)
- type Session
- type UpdatePasswordRequest
- type UpdateProfileRequest
- type User
- type VerifyEmailRequest
Constants ¶
const ( SessionCookieName = "kubebrowse_session" UserContextKey = "user" )
Variables ¶
var ( ErrUserNotFound = errors.New("user not found") ErrInvalidCredentials = errors.New("invalid credentials") ErrUserAlreadyExists = errors.New("user already exists") ErrSessionExpired = errors.New("session expired") ErrEmailNotVerified = errors.New("email not verified") ErrInvalidToken = errors.New("invalid or expired verification token") )
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware(service *Service) gin.HandlerFunc
AuthMiddleware is a middleware that validates user sessions
func OptionalAuthMiddleware ¶
func OptionalAuthMiddleware(service *Service) gin.HandlerFunc
OptionalAuthMiddleware is a middleware that optionally validates user sessions It doesn't abort the request if authentication fails, but sets user context if available
Types ¶
type AuthResponse ¶
AuthResponse represents the response for successful authentication
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
func NewHandler ¶
func NewHandlerWithRedis ¶
func (*Handler) BeginOAuth ¶
BeginOAuth starts the OAuth flow with Redis-based state management
func (*Handler) CallbackOAuth ¶
CallbackOAuth handles the OAuth callback
func (*Handler) GetCurrentUser ¶
GetCurrentUser returns the current authenticated user
func (*Handler) GetUserProfile ¶
GetUserProfile returns the current user's profile
func (*Handler) LoginWithEmail ¶
LoginWithEmail handles user login with email and password
func (*Handler) RegisterWithEmail ¶
RegisterWithEmail handles user registration with email and password
func (*Handler) ResendVerificationEmail ¶
ResendVerificationEmail handles resending verification email
func (*Handler) UpdatePassword ¶
UpdatePassword handles user password updates
func (*Handler) UpdateProfile ¶
UpdateProfile handles user profile updates
func (*Handler) VerifyEmail ¶
VerifyEmail handles email verification
type LoginRequest ¶
type LoginRequest struct {
Email string `json:"email" binding:"required,email"`
Password string `json:"password" binding:"required"`
}
LoginRequest represents the request body for email login
type RegisterRequest ¶
type RegisterRequest struct {
Email string `json:"email" binding:"required,email"`
Password string `json:"password" binding:"required,min=8"`
}
RegisterRequest represents the request body for email registration
type ResendVerificationRequest ¶
type ResendVerificationRequest struct {
Email string `json:"email" binding:"required,email"`
}
ResendVerificationRequest represents the request body for resending verification email
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) CleanupExpiredSessions ¶
CleanupExpiredSessions removes expired sessions
func (*Service) CreateOrUpdateOAuthUser ¶
func (s *Service) CreateOrUpdateOAuthUser(email, provider, providerID, avatarURL, name, username string) (*User, error)
CreateOrUpdateOAuthUser creates or updates a user from OAuth provider
func (*Service) CreateSession ¶
CreateSession creates a new session for a user
func (*Service) DeleteSession ¶
DeleteSession deletes a session
func (*Service) GetUserByID ¶
GetUserByID retrieves a user by their ID
func (*Service) LoginWithEmail ¶
LoginWithEmail authenticates a user with email and password
func (*Service) RegisterWithEmail ¶
RegisterWithEmail creates a new user with email and password
func (*Service) ResendVerificationEmail ¶
ResendVerificationEmail resends the verification email for a user
func (*Service) UpdateUserPassword ¶
UpdateUserPassword updates a user's password
func (*Service) UpdateUserProfile ¶
func (s *Service) UpdateUserProfile(userID uuid.UUID, username, name, avatarURL *string) (*User, error)
UpdateUserProfile updates a user's profile information
func (*Service) ValidateSession ¶
ValidateSession validates a session token and returns the user
type Session ¶
type Session struct {
ID uuid.UUID `json:"id"`
UserID uuid.UUID `json:"user_id"`
SessionToken string `json:"session_token"`
ExpiresAt time.Time `json:"expires_at"`
User *User `json:"user,omitempty"`
}
Session represents a user session
type UpdatePasswordRequest ¶
type UpdatePasswordRequest struct {
CurrentPassword string `json:"current_password" binding:"required"`
NewPassword string `json:"new_password" binding:"required,min=8"`
}
UpdatePasswordRequest represents the request body for password updates
type UpdateProfileRequest ¶
type UpdateProfileRequest struct {
Username *string `json:"username"`
Name *string `json:"name"`
AvatarURL *string `json:"avatar_url"`
}
UpdateProfileRequest represents the request body for profile updates
type User ¶
type User struct {
ID uuid.UUID `json:"id"`
Username *string `json:"username"`
Email string `json:"email"`
Provider string `json:"provider"`
AvatarURL *string `json:"avatar_url"`
Name *string `json:"name"`
EmailVerified bool `json:"email_verified"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
User represents a user in the system
type VerifyEmailRequest ¶
type VerifyEmailRequest struct {
Token string `json:"token" binding:"required"`
}
VerifyEmailRequest represents the request body for email verification