auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	UserID   int    `json:"user_id"`
	Username string `json:"username"`
	jwt.StandardClaims
}

Claims represents JWT claims

type RefreshClaims

type RefreshClaims struct {
	UserID  int    `json:"user_id"`
	TokenID string `json:"token_id"`
	jwt.StandardClaims
}

RefreshClaims represents JWT refresh token claims

type Service

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

Service handles user authentication

func NewService

func NewService(
	cfg *config.Config,
	log *logger.Logger,
	userRepository models.UserRepository,
) *Service

NewService creates a new auth service

func (*Service) Login

func (s *Service) Login(usernameOrEmail, password string) (*Tokens, error)

Login authenticates a user and returns tokens

func (*Service) RefreshToken

func (s *Service) RefreshToken(refreshToken string) (*Tokens, error)

RefreshToken refreshes an access token

func (*Service) Register

func (s *Service) Register(username, email, password string) (*models.User, error)

Register registers a new user

func (*Service) ValidateToken

func (s *Service) ValidateToken(accessToken string) (*Claims, error)

ValidateToken validates an access token

type Tokens

type Tokens struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_in"`
}

Tokens represents auth tokens

Jump to

Keyboard shortcuts

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