emailverification

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package emailverification binds one-time verification to a concrete model's current stored email. Verifying an email never issues an authentication proof.

Index

Constants

View Source
const DefaultLifetime = 24 * time.Hour

Variables

This section is empty.

Functions

This section is empty.

Types

type Issued

Issued carries a committed email-verification challenge for model M.

type Model

type Model[M model.Identifiable, K any] struct {
	Lock          func(context.Context, *database.Tx, K) (value.Optional[M], error)
	Email         func(M) string
	EmailRevision func(M) challenge.Revision[M]
	Verified      func(M) bool
	MarkVerified  func(context.Context, *database.Tx, M) (M, error)
	Eligible      func(context.Context, M) (bool, error)
}

Model maps stored email state. EmailRevision must be persisted and replaced transactionally whenever Email changes; restoring an old address must never restore its old revision. MarkVerified must preserve email and revision. Eligible optionally replaces the provider's eligibility for this flow, for example when the provider only admits accounts with verified addresses.

type Token

Token is an email-verification secret retaining its model type.

func ParseToken

func ParseToken[M any](raw secret.String) (Token[M], error)

ParseToken validates verification-token syntax without checking its stored validity.

type Verification

type Verification[M model.Identifiable, K any] struct {
	// contains filtered or unexported fields
}

Verification owns the typed single-use email-verification flow and its model callbacks.

func New

func New[M model.Identifiable, K any](store *challenge.Store, provider auth.Provider[M, K], binding Model[M, K], lifetime time.Duration) (*Verification[M, K], error)

New validates model callbacks and binds an email-verification flow to the current email and revision.

func (*Verification[M, K]) Complete

func (v *Verification[M, K]) Complete(ctx context.Context, token Token[M]) (M, error)

Complete consumes the token and marks the unchanged email verified in one transaction, then notifies the observer after success.

func (*Verification[M, K]) Issue

func (v *Verification[M, K]) Issue(ctx context.Context, reference model.Reference[M, K]) (Issued[M], error)

Issue uses the model's currently locked email for binding. Applications deliver only to the issued Subject's stored email and use a uniform public response.

func (*Verification[M, K]) Prune

func (v *Verification[M, K]) Prune(ctx context.Context, limit int) (uint64, error)

Prune removes up to limit expired verification challenges.

func (*Verification[M, K]) Revoke

func (v *Verification[M, K]) Revoke(ctx context.Context, reference model.Reference[M, K]) (bool, error)

Revoke removes the subject's verification challenge and reports whether one existed.

func (*Verification[M, K]) Validate

func (v *Verification[M, K]) Validate() error

Validate checks that the verification flow is configured.

func (*Verification[M, K]) WithObserver

func (v *Verification[M, K]) WithObserver(observer auth.Observer) (*Verification[M, K], error)

WithObserver reports EventVerified after each committed verification.

Jump to

Keyboard shortcuts

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