auth

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRoleFromContext

func GetRoleFromContext(c ctx.Ctx) (string, bool)

GetRoleFromContext extracts user role from context

func GetUserFromContext

func GetUserFromContext(c ctx.Ctx) (*jwt.Claims, bool)

GetUserFromContext extracts user claims from context

func GetUserIDFromContext

func GetUserIDFromContext(c ctx.Ctx) (string, bool)

GetUserIDFromContext extracts user ID from context

func HasAnyRole

func HasAnyRole(c ctx.Ctx, roles ...string) bool

HasAnyRole checks if the current user has any of the specified roles

func HasRole

func HasRole(c ctx.Ctx, role string) bool

HasRole checks if the current user has a specific role

func IsAuthenticated

func IsAuthenticated(c ctx.Ctx) bool

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) Login

func (h *Handlers) Login() ctx.Handler

Login handles user login

func (*Handlers) Logout

func (h *Handlers) Logout() ctx.Handler

Logout handles user logout

func (*Handlers) Me

func (h *Handlers) Me() ctx.Handler

Me returns the current authenticated user's information

func (*Handlers) Refresh

func (h *Handlers) Refresh() ctx.Handler

Refresh handles token refresh with rotation

func (*Handlers) RequestPasswordReset

func (h *Handlers) RequestPasswordReset() ctx.Handler

RequestPasswordReset handles password reset requests

func (*Handlers) ResetPassword

func (h *Handlers) ResetPassword() ctx.Handler

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

type RefreshResponse

type RefreshResponse struct {
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token"`
	ExpiresAt    time.Time `json:"expires_at"`
}

RefreshResponse represents a token refresh response

type UserInfo

type UserInfo struct {
	ID       string `json:"id"`
	Username string `json:"username"`
	Email    string `json:"email"`
	Name     string `json:"name"`
	Role     string `json:"role"`
}

UserInfo represents user information returned after login

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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