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
- type Issued
- type Model
- type Token
- type Verification
- func (v *Verification[M, K]) Complete(ctx context.Context, token Token[M]) (M, error)
- func (v *Verification[M, K]) Issue(ctx context.Context, reference model.Reference[M, K]) (Issued[M], error)
- func (v *Verification[M, K]) Prune(ctx context.Context, limit int) (uint64, error)
- func (v *Verification[M, K]) Revoke(ctx context.Context, reference model.Reference[M, K]) (bool, error)
- func (v *Verification[M, K]) Validate() error
- func (v *Verification[M, K]) WithObserver(observer auth.Observer) (*Verification[M, K], error)
Constants ¶
const DefaultLifetime = 24 * time.Hour
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Issued ¶
type Issued[M any] = challenge.Issued[M, challenge.EmailVerification]
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 ¶
type Token[M any] = challenge.Token[M, challenge.EmailVerification]
Token is an email-verification secret retaining its model type.
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]) 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.