auth

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMFARequired          = errors.New("mfa is required")
	ErrInvalidMFACode       = errors.New("invalid mfa code")
	ErrInvalidPassword      = errors.New("invalid password")
	ErrMFASecretUnavailable = errors.New("mfa secret unavailable")
)
View Source
var (
	ErrInvalidCredentials = errors.New("invalid credentials")
	ErrSSONotConfigured   = errors.New("sso_not_configured")
	ErrSSODisabled        = errors.New("sso_disabled")
	ErrInvalidToken       = errors.New("invalid_token")
	ErrUserNotFound       = errors.New("user_not_found")
	ErrSSONotAllowed      = errors.New("sso_not_allowed")
)

Functions

func DecryptEmail

func DecryptEmail(ciphertext string, key []byte) (string, error)

func EncryptEmail

func EncryptEmail(plain string, key []byte) (string, error)

func HashEmail

func HashEmail(normalized string) string

func NormalizeEmail

func NormalizeEmail(email string) string

Types

type CreateInvitationRequest

type CreateInvitationRequest struct {
	Email     string
	Role      string
	CreatedBy primitive.ObjectID
	TokenHash string
	ExpiresAt time.Time
}

type CreateUserRequest

type CreateUserRequest struct {
	Username  string
	Email     string
	Role      string
	Status    string
	InvitedBy *primitive.ObjectID
	Password  string
}

type DisableMFARequest

type DisableMFARequest struct {
	UserID   string
	Password string
	Code     string
}

type LoginRequest

type LoginRequest struct {
	Email    string
	Password string
}

type LoginResult

type LoginResult struct {
	Token string
	User  struct {
		ID       string
		Username string
		Email    string
		Role     string
	}
	MFARequired bool
}

type MFAService

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

func NewMFAService

func NewMFAService(repo repository.UserRepository, jwtSecret, mfaSecretKey, emailEncryptionKey, issuer string) *MFAService

func (*MFAService) DisableMFA

func (s *MFAService) DisableMFA(ctx context.Context, req DisableMFARequest) error

func (*MFAService) GetUserByID

func (s *MFAService) GetUserByID(ctx context.Context, id string) (*models.User, error)

func (*MFAService) StartEnrollment

func (s *MFAService) StartEnrollment(ctx context.Context, userID string) (*StartEnrollmentResult, error)

func (*MFAService) UpdateProfile

func (s *MFAService) UpdateProfile(ctx context.Context, req UpdateProfileRequest) error

func (*MFAService) VerifyChallenge

func (*MFAService) VerifyEnrollment

type Service

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

func NewService

func NewService(repo repository.UserRepository, jwtSecret, emailEncryptionKey string) *Service

func NewServiceFromDB

func NewServiceFromDB(db *mongo.Database, jwtSecret, emailEncryptionKey string) *Service

func NewServiceWithSettings

func NewServiceWithSettings(repo repository.UserRepository, settingsRepo repository.SettingsRepository, jwtSecret, emailEncryptionKey string) *Service

func (*Service) AuthenticateSSO

func (s *Service) AuthenticateSSO(ctx context.Context, rawToken string) (*LoginResult, error)

func (*Service) CreateInvitation

func (s *Service) CreateInvitation(ctx context.Context, req CreateInvitationRequest) (*models.UserInvitation, error)

func (*Service) CreateUser

func (s *Service) CreateUser(ctx context.Context, req CreateUserRequest) (*models.User, error)

func (*Service) DecryptStoredEmail

func (s *Service) DecryptStoredEmail(ciphertext string) (string, error)

func (*Service) EmailExists

func (s *Service) EmailExists(ctx context.Context, email string) (bool, error)

func (*Service) EncryptForStorage

func (s *Service) EncryptForStorage(email string) (encrypted string, emailHash string, normalized string, err error)

func (*Service) FindUserByEmail

func (s *Service) FindUserByEmail(ctx context.Context, email string) (*models.User, error)

func (*Service) GetUserByID

func (s *Service) GetUserByID(ctx context.Context, id string) (*models.User, error)

func (*Service) Login

func (s *Service) Login(ctx context.Context, req LoginRequest) (*LoginResult, error)

type StartEnrollmentResult

type StartEnrollmentResult struct {
	Secret        string
	OTPAuthURL    string
	RecoveryCodes []string
}

type UpdateProfileRequest

type UpdateProfileRequest struct {
	UserID          string
	Username        string
	CurrentPassword string
	NewPassword     string
}

type VerifyChallengeRequest

type VerifyChallengeRequest struct {
	UserID string
	Code   string
}

type VerifyChallengeResult

type VerifyChallengeResult struct {
	Token       string
	MFAVerified bool
}

type VerifyEnrollmentRequest

type VerifyEnrollmentRequest struct {
	UserID string
	Code   string
}

Jump to

Keyboard shortcuts

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