challenge

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrChallengeExpired            = errors.New("challenge expired")
	ErrChallengeConsumed           = errors.New("challenge already consumed")
	ErrTooManyAttempts             = errors.New("too many verification attempts")
	ErrTooManyResends              = errors.New("too many resend attempts")
	ErrResendTooSoon               = errors.New("resend requested too soon")
	ErrInvalidVerificationCode     = errors.New("invalid verification code")
	ErrUnsupportedChallengePurpose = errors.New("unsupported challenge purpose")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Store                  *store.Store
	Tx                     *tx.Manager
	AllowlistEnabled       bool
	ChallengeTTL           time.Duration
	MaxAttempts            int
	MaxResends             int
	MinResendInterval      time.Duration
	WebhookPublisher       webhook.Publisher
	AccessTokenRevocations *token.AccessTokenRevocations
}

type CreateEmailChangeChallengeInput added in v0.1.15

type CreateEmailChangeChallengeInput struct {
	UserID   uuid.UUID
	OldEmail string
	NewEmail string
}

type CreatePasswordResetChallengeInput added in v0.1.14

type CreatePasswordResetChallengeInput struct {
	UserID       uuid.UUID
	Email        string
	PasswordHash string
}

type CreateSignupChallengeInput

type CreateSignupChallengeInput struct {
	Email        string
	Username     string
	PasswordHash string
	InvitationID *uuid.UUID
}

type EmailTemplateRenderer added in v0.20.0

type EmailTemplateRenderer interface {
	Render(context.Context, domain.EmailTemplate, email.TemplateData) (email.Message, error)
}

type Service

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

func New

func New(cfg Config) *Service

func (*Service) CreateEmailChangeChallenge added in v0.1.15

func (s *Service) CreateEmailChangeChallenge(
	ctx context.Context,
	in CreateEmailChangeChallengeInput,
	now time.Time,
) (uuid.UUID, error)

func (*Service) CreateOpaqueChallenge

func (s *Service) CreateOpaqueChallenge(
	ctx context.Context,
	now time.Time,
	purpose domain.ChallengePurpose,
	email string,
) (uuid.UUID, error)

func (*Service) CreatePasswordResetChallenge added in v0.1.14

func (s *Service) CreatePasswordResetChallenge(
	ctx context.Context,
	in CreatePasswordResetChallengeInput,
	now time.Time,
) (uuid.UUID, error)

func (*Service) CreateSignupChallenge

func (s *Service) CreateSignupChallenge(
	ctx context.Context,
	in CreateSignupChallengeInput,
	now time.Time,
) (uuid.UUID, error)

func (*Service) ExecuteEmailChange added in v0.1.15

func (s *Service) ExecuteEmailChange(
	ctx context.Context,
	action domain.PendingEmailChange,
	now time.Time,
) error

func (*Service) ExecutePasswordReset added in v0.1.14

func (s *Service) ExecutePasswordReset(
	ctx context.Context,
	action domain.PendingPasswordReset,
	now time.Time,
) error

func (*Service) ResendChallenge

func (s *Service) ResendChallenge(
	ctx context.Context,
	challengeID uuid.UUID,
	now time.Time,
) error

func (*Service) VerifyEmailChangeChallenge added in v0.1.15

func (s *Service) VerifyEmailChangeChallenge(
	ctx context.Context,
	challengeID uuid.UUID,
	code string,
	verifier *VerificationCodeService,
	now time.Time,
) (*VerifyEmailChangeChallengeResult, error)

func (*Service) VerifyPasswordResetChallenge added in v0.1.14

func (s *Service) VerifyPasswordResetChallenge(
	ctx context.Context,
	challengeID uuid.UUID,
	code string,
	verifier *VerificationCodeService,
	now time.Time,
) (*VerifyPasswordResetChallengeResult, error)

func (*Service) VerifySignupChallenge

func (s *Service) VerifySignupChallenge(
	ctx context.Context,
	challengeID uuid.UUID,
	code string,
	verifier *VerificationCodeService,
	now time.Time,
	complete func(context.Context, domain.PendingSignupAction) error,
) (*VerifySignupChallengeResult, error)

type VerificationCodeService

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

func NewVerificationCodeService

func NewVerificationCodeService(store *store.Store, ttl time.Duration, secrets ...[]byte) *VerificationCodeService

func (*VerificationCodeService) GenerateCode

func (s *VerificationCodeService) GenerateCode(
	ctx context.Context,
	challenge domain.Challenge,
	now time.Time,
) (string, error)

func (*VerificationCodeService) VerifyCode

func (s *VerificationCodeService) VerifyCode(
	ctx context.Context,
	challengeID uuid.UUID,
	code string,
	now time.Time,
) error

type VerifyEmailChangeChallengeResult added in v0.1.15

type VerifyEmailChangeChallengeResult struct {
	Challenge domain.Challenge
	Action    domain.PendingEmailChange
}

type VerifyPasswordResetChallengeResult added in v0.1.14

type VerifyPasswordResetChallengeResult struct {
	Challenge domain.Challenge
	Action    domain.PendingPasswordReset
}

type VerifySignupChallengeResult

type VerifySignupChallengeResult struct {
	Challenge domain.Challenge
	Action    domain.PendingSignupAction
}

type Worker

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

func NewWorker

func NewWorker(
	store *store.Store,
	codeSvc *VerificationCodeService,
	templates EmailTemplateRenderer,
	sender email.Sender,
	logger *slog.Logger,
	cfg WorkerConfig,
) *Worker

func (*Worker) Run

func (w *Worker) Run(ctx context.Context)

func (*Worker) RunOnce

func (w *Worker) RunOnce(ctx context.Context, now time.Time) (bool, error)

type WorkerConfig

type WorkerConfig struct {
	WorkerCount        int
	PollInterval       time.Duration
	JobMaxAttempts     int
	CleanupSentAfter   time.Duration
	CleanupFailedAfter time.Duration
	CleanupInterval    time.Duration
	SendTimeout        time.Duration
	Metrics            WorkerMetrics
}

type WorkerMetrics added in v0.19.0

type WorkerMetrics interface {
	ObserveBackgroundJob(worker, outcome string, duration time.Duration)
}

Jump to

Keyboard shortcuts

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