auth

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCookieName = "emerald_session"
	DefaultSessionTTL = 24 * time.Hour
)

Variables

View Source
var ErrInvalidCredentials = errors.New("invalid credentials")

Functions

This section is empty.

Types

type Config

type Config struct {
	SessionTTL time.Duration
	CookieName string
}

type Service

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

func NewService

func NewService(users UserStore, cfg Config) *Service

func (*Service) Authenticate

func (s *Service) Authenticate(ctx context.Context, username string, password string) (*models.User, error)

func (*Service) CookieName

func (s *Service) CookieName() string

func (*Service) Login

func (s *Service) Login(ctx context.Context, username string, password string) (string, Session, error)

func (*Service) Logout

func (s *Service) Logout(token string)

func (*Service) RevokeUserSessions

func (s *Service) RevokeUserSessions(userID string)

func (*Service) Session

func (s *Service) Session(token string) (Session, bool)

type Session

type Session struct {
	UserID    string
	Username  string
	ExpiresAt time.Time
}

type UserStore

type UserStore interface {
	GetByUsername(ctx context.Context, username string) (*models.User, error)
}

Jump to

Keyboard shortcuts

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