mfa

package
v0.0.0-...-f553eaf Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: Apache-2.0 Imports: 22 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDeviceTokenNotFound = errors.New("bearer token not found")
View Source
var ErrRecoveryCodeConsumed = errors.New("recovery code consumed")
View Source
var ErrRecoveryCodeNotFound = errors.New("recovery code not found")

Functions

func GenerateDeviceToken

func GenerateDeviceToken() string

Types

type CookieDef

type CookieDef struct {
	Def *httputil.CookieDef
}

func NewDeviceTokenCookieDef

func NewDeviceTokenCookieDef(cfg *config.AuthenticationConfig) CookieDef

type DeviceToken

type DeviceToken struct {
	UserID    string    `json:"-"`
	Token     string    `json:"-"`
	CreatedAt time.Time `json:"created_at"`
	ExpireAt  time.Time `json:"expire_at"`
}

type Lockout

type Lockout struct {
	Config   *config.AuthenticationLockoutConfig
	RemoteIP httputil.RemoteIP
	Provider LockoutProvider
}

func (*Lockout) Check

func (l *Lockout) Check(ctx context.Context, userID string) error

func (*Lockout) MakeRecoveryCodeAttempt

func (l *Lockout) MakeRecoveryCodeAttempt(ctx context.Context, userID string, attempts int) error

type LockoutProvider

type LockoutProvider interface {
	MakeAttempts(ctx context.Context, spec lockout.LockoutSpec, contributor string, attempts int) (result *lockout.MakeAttemptResult, err error)
}

type RateLimiter

type RateLimiter interface {
	Reserve(ctx context.Context, spec ratelimit.BucketSpec) (*ratelimit.Reservation, *ratelimit.FailedReservation, error)
	Cancel(ctx context.Context, r *ratelimit.Reservation)
}

type ReadOnlyService

type ReadOnlyService struct {
	RecoveryCodes StoreRecoveryCode
}

RateLimiter depends on EventService EventService depends on UserInfoService So finally depends on mfa.Service causing circular dependency This service was created for read only methods and do not depends on RateLimiter to break this circular dependency

func (*ReadOnlyService) ListRecoveryCodes

func (s *ReadOnlyService) ListRecoveryCodes(ctx context.Context, userID string) ([]*RecoveryCode, error)

type RecoveryCode

type RecoveryCode struct {
	ID        string    `json:"id"`
	UserID    string    `json:"user_id"`
	Code      string    `json:"code"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Consumed  bool      `json:"consumed"`
}

type Service

type Service struct {
	ReadOnlyService
	IP            httputil.RemoteIP
	DeviceTokens  StoreDeviceToken
	RecoveryCodes StoreRecoveryCode
	Clock         clock.Clock
	Config        *config.AppConfig
	FeatureConfig *config.FeatureConfig
	EnvConfig     *config.RateLimitsEnvironmentConfig
	RateLimiter   RateLimiter
	Lockout       Lockout
}

func (*Service) ConsumeRecoveryCode

func (s *Service) ConsumeRecoveryCode(ctx context.Context, rc *RecoveryCode) error

func (*Service) CountDeviceTokens

func (s *Service) CountDeviceTokens(ctx context.Context, userID string) (int, error)

func (*Service) CreateDeviceToken

func (s *Service) CreateDeviceToken(ctx context.Context, userID string, token string) (*DeviceToken, error)

func (*Service) GenerateDeviceToken

func (s *Service) GenerateDeviceToken(ctx context.Context) string

func (*Service) GenerateRecoveryCodes

func (s *Service) GenerateRecoveryCodes(ctx context.Context) []string

func (*Service) HasDeviceTokens

func (s *Service) HasDeviceTokens(ctx context.Context, userID string) (bool, error)

func (*Service) InvalidateAllDeviceTokens

func (s *Service) InvalidateAllDeviceTokens(ctx context.Context, userID string) error

func (*Service) InvalidateAllRecoveryCode

func (s *Service) InvalidateAllRecoveryCode(ctx context.Context, userID string) error

func (*Service) ReplaceRecoveryCodes

func (s *Service) ReplaceRecoveryCodes(ctx context.Context, userID string, codes []string) ([]*RecoveryCode, error)

func (*Service) VerifyDeviceToken

func (s *Service) VerifyDeviceToken(ctx context.Context, userID string, token string) error

func (*Service) VerifyRecoveryCode

func (s *Service) VerifyRecoveryCode(ctx context.Context, userID string, code string) (*RecoveryCode, error)

type StoreDeviceToken

type StoreDeviceToken interface {
	Get(ctx context.Context, userID string, token string) (*DeviceToken, error)
	Create(ctx context.Context, token *DeviceToken) error
	DeleteAll(ctx context.Context, userID string) error
	HasTokens(ctx context.Context, userID string) (bool, error)
	Count(ctx context.Context, userID string) (int, error)
}

type StoreDeviceTokenRedis

type StoreDeviceTokenRedis struct {
	Redis *appredis.Handle
	AppID config.AppID
	Clock clock.Clock
}

func (*StoreDeviceTokenRedis) Count

func (s *StoreDeviceTokenRedis) Count(ctx context.Context, userID string) (int, error)

func (*StoreDeviceTokenRedis) Create

func (s *StoreDeviceTokenRedis) Create(ctx context.Context, token *DeviceToken) error

func (*StoreDeviceTokenRedis) DeleteAll

func (s *StoreDeviceTokenRedis) DeleteAll(ctx context.Context, userID string) error

func (*StoreDeviceTokenRedis) Get

func (s *StoreDeviceTokenRedis) Get(ctx context.Context, userID string, token string) (*DeviceToken, error)

func (*StoreDeviceTokenRedis) HasTokens

func (s *StoreDeviceTokenRedis) HasTokens(ctx context.Context, userID string) (bool, error)

type StoreRecoveryCode

type StoreRecoveryCode interface {
	List(ctx context.Context, userID string) ([]*RecoveryCode, error)
	Get(ctx context.Context, userID string, code string) (*RecoveryCode, error)
	DeleteAll(ctx context.Context, userID string) error
	CreateAll(ctx context.Context, codes []*RecoveryCode) error
	UpdateConsumed(ctx context.Context, code *RecoveryCode) error
}

type StoreRecoveryCodePQ

type StoreRecoveryCodePQ struct {
	SQLBuilder  *appdb.SQLBuilderApp
	SQLExecutor *appdb.SQLExecutor
}

func (*StoreRecoveryCodePQ) CreateAll

func (s *StoreRecoveryCodePQ) CreateAll(ctx context.Context, codes []*RecoveryCode) error

func (*StoreRecoveryCodePQ) DeleteAll

func (s *StoreRecoveryCodePQ) DeleteAll(ctx context.Context, userID string) error

func (*StoreRecoveryCodePQ) Get

func (s *StoreRecoveryCodePQ) Get(ctx context.Context, userID string, code string) (*RecoveryCode, error)

func (*StoreRecoveryCodePQ) List

func (s *StoreRecoveryCodePQ) List(ctx context.Context, userID string) ([]*RecoveryCode, error)

func (*StoreRecoveryCodePQ) UpdateConsumed

func (s *StoreRecoveryCodePQ) UpdateConsumed(ctx context.Context, code *RecoveryCode) error

Jump to

Keyboard shortcuts

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