token

package
v0.0.0-...-264fe26 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoTokenFound = errors.New("token_store: token not found")
View Source
var ErrTokenInactive = errors.New("tokenservice: token inactive")
View Source
var ErrTokenValidation = errors.New("tokenservice: invalid token format")
View Source
var ErrTokenVerification = errors.New("tokenservice: wrong token code")

Functions

func Validate

func Validate(code string) error

Types

type CodeToken

type CodeToken struct {
	Value       string
	HashedValue [32]byte
	ExpireAt    time.Time
	OwnerID     string
	Attempts    int
}

type Config

type Config interface {
	GetDuration() (time.Duration, error)
	GetAttempts() (int, error)
}

type HTMLTemplateMessage

type HTMLTemplateMessage struct {
	Tmplt    *template.Template
	MapToken func(token *CodeToken) interface{}
}

func NewHTMLMessageBuilder

func NewHTMLMessageBuilder(templatePath string, mapTokenFunc func(token *CodeToken) interface{}) (*HTMLTemplateMessage, error)

func (*HTMLTemplateMessage) GetMessage

func (mb *HTMLTemplateMessage) GetMessage(token *CodeToken) (string, error)

type MessageBuilder

type MessageBuilder interface {
	GetMessage(token *CodeToken) (string, error)
}

type Service

type Service interface {
	Verify(ctx context.Context, ownerID string, code string) error
	CreateAndDeliver(ctx context.Context, ownerID string, destination string) error
}

type SimpleMessage

type SimpleMessage struct{}

func (*SimpleMessage) GetMessage

func (mb *SimpleMessage) GetMessage(token *CodeToken) (string, error)

type SimpleTokenConfig

type SimpleTokenConfig struct {
	Duration time.Duration
	Attempts int
}

func (*SimpleTokenConfig) GetAttempts

func (c *SimpleTokenConfig) GetAttempts() (int, error)

func (*SimpleTokenConfig) GetDuration

func (c *SimpleTokenConfig) GetDuration() (time.Duration, error)

type Store

type Store interface {
	Save(ctx context.Context, token *CodeToken) error
	DecreaseAttemptAndLoadLatest(ctx context.Context, uid string) (*CodeToken, error)
}

type TokenService

type TokenService struct {
	Logger         logr.Logger
	Store          Store
	Conf           Config
	Transport      Transport
	MessageBuilder MessageBuilder
	CtxReqIDKey    interface{}
}

func (*TokenService) CreateAndDeliver

func (ts *TokenService) CreateAndDeliver(ctx context.Context, ownerID, destination string) error

func (*TokenService) Verify

func (ts *TokenService) Verify(ctx context.Context, ownerID, code string) error

type Transport

type Transport interface {
	Send(ctx context.Context, msg string, receiver string) error
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
store
mem
transport

Jump to

Keyboard shortcuts

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