auth

package
v0.0.0-...-4aa44aa Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")
View Source
var ErrUnauthorized = errors.New("unauthorized")
View Source
var ErrUsernameTaken = errors.New("username taken")

Functions

This section is empty.

Types

type AccessToken

type AccessToken string

type AccessTokenGenerator

type AccessTokenGenerator interface {
	Generate(username string) (AccessToken, error)
	GetUsername(token AccessToken) (string, error)
}

type Auth

type Auth struct {
	RegisterInitial  *RegisterInitialHandler
	Register         *RegisterHandler
	Login            *LoginHandler
	Logout           *LogoutHandler
	CheckAccessToken *CheckAccessTokenHandler
	List             *ListHandler
	CreateInvitation *CreateInvitationHandler
	Remove           *RemoveHandler
	SetPassword      *SetPasswordHandler
}

type CheckAccessToken

type CheckAccessToken struct {
	Token AccessToken
}

type CheckAccessTokenHandler

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

func NewCheckAccessTokenHandler

func NewCheckAccessTokenHandler(
	transactionProvider TransactionProvider,
	accessTokenGenerator AccessTokenGenerator,
	lastSeenUpdater LastSeenUpdater,
) *CheckAccessTokenHandler

func (*CheckAccessTokenHandler) Execute

type CreateInvitationHandler

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

func NewCreateInvitationHandler

func NewCreateInvitationHandler(
	cryptoStringGenerator CryptoStringGenerator,
	transactionProvider TransactionProvider,
) *CreateInvitationHandler

func (*CreateInvitationHandler) Execute

type CryptoStringGenerator

type CryptoStringGenerator interface {
	Generate(bytes int) (string, error)
}

type Invitation

type Invitation struct {
	Token   InvitationToken `json:"invitation"`
	Created time.Time       `json:"created"`
}

type InvitationRepository

type InvitationRepository interface {
	// Put inserts the invitation into the repository. The previous entry
	// with this token is overwriten.
	Put(invitation Invitation) error

	// Get returns an invitation with the provided token, if the invitation
	// doesn't exist ErrNotFound is returned.
	Get(token InvitationToken) (*Invitation, error)

	// Remove removes an invitation. If the invitation doesn't exist this
	// function returns nil.
	Remove(token InvitationToken) error
}

type InvitationToken

type InvitationToken string

type LastSeenUpdater

type LastSeenUpdater interface {
	Update(username string, token AccessToken, t time.Time)
}

type ListHandler

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

func NewListHandler

func NewListHandler(transactionProvider TransactionProvider) *ListHandler

func (*ListHandler) Execute

func (h *ListHandler) Execute() ([]ReadUser, error)

type Login

type Login struct {
	Username string
	Password string
}

type LoginHandler

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

func NewLoginHandler

func NewLoginHandler(
	passwordHasher PasswordHasher,
	transactionProvider TransactionProvider,
	accessTokenGenerator AccessTokenGenerator,
) *LoginHandler

func (*LoginHandler) Execute

func (h *LoginHandler) Execute(cmd Login) (AccessToken, error)

type Logout

type Logout struct {
	Token AccessToken
}

type LogoutHandler

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

func NewLogoutHandler

func NewLogoutHandler(
	transactionProvider TransactionProvider,
	accessTokenGenerator AccessTokenGenerator,
) *LogoutHandler

func (*LogoutHandler) Execute

func (h *LogoutHandler) Execute(cmd Logout) error

type PasswordHash

type PasswordHash []byte

type PasswordHasher

type PasswordHasher interface {
	Hash(password string) (PasswordHash, error)
	Compare(hashedPassword PasswordHash, password string) error
}

type ReadSession

type ReadSession struct {
	LastSeen time.Time `json:"lastSeen"`
}

type ReadUser

type ReadUser struct {
	Username      string        `json:"username"`
	Administrator bool          `json:"administrator"`
	Created       time.Time     `json:"created"`
	LastSeen      time.Time     `json:"lastSeen"`
	Sessions      []ReadSession `json:"sessions"`
}

type Register

type Register struct {
	Username string
	Password string
	Token    InvitationToken
}

type RegisterHandler

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

func NewRegisterHandler

func NewRegisterHandler(
	passwordHasher PasswordHasher,
	transactionProvider TransactionProvider,
) *RegisterHandler

func (*RegisterHandler) Execute

func (h *RegisterHandler) Execute(cmd Register) error

type RegisterInitial

type RegisterInitial struct {
	Username string
	Password string
}

type RegisterInitialHandler

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

func NewRegisterInitialHandler

func NewRegisterInitialHandler(
	passwordHasher PasswordHasher,
	transactionProvider TransactionProvider,
) *RegisterInitialHandler

func (*RegisterInitialHandler) Execute

type Remove

type Remove struct {
	Username string
}

type RemoveHandler

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

func NewRemoveHandler

func NewRemoveHandler(transactionProvider TransactionProvider) *RemoveHandler

func (*RemoveHandler) Execute

func (h *RemoveHandler) Execute(cmd Remove) error

type Session

type Session struct {
	Token    AccessToken `json:"token"`
	LastSeen time.Time   `json:"lastSeen"`
}

type SetPassword

type SetPassword struct {
	Username string
	Password string
}

type SetPasswordHandler

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

func NewSetPasswordHandler

func NewSetPasswordHandler(
	passwordHasher PasswordHasher,
	transactionProvider TransactionProvider,
) *SetPasswordHandler

func (*SetPasswordHandler) Execute

func (h *SetPasswordHandler) Execute(cmd SetPassword) error

type TransactableRepositories

type TransactableRepositories struct {
	Invitations InvitationRepository
	Users       UserRepository
}

type TransactionHandler

type TransactionHandler func(repositories *TransactableRepositories) error

type TransactionProvider

type TransactionProvider interface {
	Read(handler TransactionHandler) error
	Write(handler TransactionHandler) error
}

type User

type User struct {
	Username      string       `json:"username"`
	Password      PasswordHash `json:"password"`
	Administrator bool         `json:"administrator"`
	Created       time.Time    `json:"created"`
	LastSeen      time.Time    `json:"lastSeen"`
	Sessions      []Session    `json:"sessions"`
}

type UserRepository

type UserRepository interface {
	// Put inserts the user into the repository. The previous entry with
	// this username is overwriten.
	Put(user User) error

	// Get returns the user with the provided username. If the user doesn't
	// exist ErrNotFound is returned.
	Get(username string) (*User, error)

	// Remove should remove a user.
	Remove(username string) error

	// List should return a list of all users.
	List() ([]User, error)

	// Count returns the number of users.
	Count() (int, error)
}

Jump to

Keyboard shortcuts

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