auth

package
v0.0.0-...-0d82576 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSessionID

func NewSessionID(n int) (string, error)

Types

type AuthRepository

type AuthRepository interface {
	GetUserByUsername(ctx context.Context, username string) (UserWithPassword, error)
	AddUser(ctx context.Context, params UserWithPassword) error
	GetSession(ctx context.Context, sessionID string) (Session, error)
	CreateSession(ctx context.Context, session Session) error
}

type AuthService

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

func NewAuthService

func NewAuthService(params NewAuthServiceParams) *AuthService

func (*AuthService) AuthenticateSession

func (srv *AuthService) AuthenticateSession(ctx context.Context, sessionID string) (User, error)

func (*AuthService) AuthenticateWithPassword

func (srv *AuthService) AuthenticateWithPassword(ctx context.Context, creds PasswordCredentials) (User, error)

func (*AuthService) CreateSession

func (srv *AuthService) CreateSession(ctx context.Context, user User) (*Session, error)

func (*AuthService) Register

func (srv *AuthService) Register(ctx context.Context, creds PasswordCredentials) (User, error)

type Clock

type Clock interface {
	Now() time.Time
}

type NewAuthServiceParams

type NewAuthServiceParams struct {
	Repository AuthRepository
	Clock      Clock
}

type PasswordCredentials

type PasswordCredentials struct {
	Username string
	Password string
}

type Session

type Session struct {
	ID           string
	User         User
	CreatedAt    time.Time
	RevokedAt    time.Time
	ExpiresAt    time.Time
	LastActiveAt time.Time
	IsRevoked    bool
}

func NewSession

func NewSession(user User) (*Session, error)

type User

type User struct {
	ID       int32
	Password string
	Username string
}

type UserWithPassword

type UserWithPassword struct {
	User
	Password string
}

Jump to

Keyboard shortcuts

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