auth

package
v0.0.0-...-1d330fa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2025 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionCookieName = "kubebrowse_session"
	UserContextKey    = "user"
)

Variables

View Source
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 InitializeGoth

func InitializeGoth()

InitializeGoth initializes the Goth OAuth providers

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

type AuthResponse struct {
	User    *User  `json:"user"`
	Message string `json:"message"`
}

AuthResponse represents the response for successful authentication

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(service *Service) *Handler

func NewHandlerWithRedis

func NewHandlerWithRedis(service *Service, redisClient *redis.Client) *Handler

func (*Handler) BeginOAuth

func (h *Handler) BeginOAuth(c *gin.Context)

BeginOAuth starts the OAuth flow with Redis-based state management

func (*Handler) CallbackOAuth

func (h *Handler) CallbackOAuth(c *gin.Context)

CallbackOAuth handles the OAuth callback

func (*Handler) GetCurrentUser

func (h *Handler) GetCurrentUser(c *gin.Context)

GetCurrentUser returns the current authenticated user

func (*Handler) GetUserProfile

func (h *Handler) GetUserProfile(c *gin.Context)

GetUserProfile returns the current user's profile

func (*Handler) LoginWithEmail

func (h *Handler) LoginWithEmail(c *gin.Context)

LoginWithEmail handles user login with email and password

func (*Handler) Logout

func (h *Handler) Logout(c *gin.Context)

Logout handles user logout

func (*Handler) RegisterWithEmail

func (h *Handler) RegisterWithEmail(c *gin.Context)

RegisterWithEmail handles user registration with email and password

func (*Handler) ResendVerificationEmail

func (h *Handler) ResendVerificationEmail(c *gin.Context)

ResendVerificationEmail handles resending verification email

func (*Handler) UpdatePassword

func (h *Handler) UpdatePassword(c *gin.Context)

UpdatePassword handles user password updates

func (*Handler) UpdateProfile

func (h *Handler) UpdateProfile(c *gin.Context)

UpdateProfile handles user profile updates

func (*Handler) VerifyEmail

func (h *Handler) VerifyEmail(c *gin.Context)

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 NewService

func NewService(db *sqlc.Queries, dbConn *sql.DB) *Service

func (*Service) CleanupExpiredSessions

func (s *Service) CleanupExpiredSessions() error

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

func (s *Service) CreateSession(userID uuid.UUID) (*Session, error)

CreateSession creates a new session for a user

func (*Service) DeleteSession

func (s *Service) DeleteSession(token string) error

DeleteSession deletes a session

func (*Service) GetUserByID

func (s *Service) GetUserByID(userID uuid.UUID) (*User, error)

GetUserByID retrieves a user by their ID

func (*Service) LoginWithEmail

func (s *Service) LoginWithEmail(email, password string) (*User, *Session, error)

LoginWithEmail authenticates a user with email and password

func (*Service) RegisterWithEmail

func (s *Service) RegisterWithEmail(email, password string) (*User, error)

RegisterWithEmail creates a new user with email and password

func (*Service) ResendVerificationEmail

func (s *Service) ResendVerificationEmail(email string) error

ResendVerificationEmail resends the verification email for a user

func (*Service) UpdateUserPassword

func (s *Service) UpdateUserPassword(userID uuid.UUID, newPassword string) error

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

func (s *Service) ValidateSession(token string) (*User, *Session, error)

ValidateSession validates a session token and returns the user

func (*Service) VerifyEmail

func (s *Service) VerifyEmail(token string) (*User, error)

VerifyEmail verifies a user's email using the verification token

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL