Skip to main content

Module magic_link_use_cases

Module magic_link_use_cases 

Source
Expand description

Use cases for the MagicLink feature (Story 3.2 — FR6, INV-13, INV-17).

Two operations:

  1. MagicLinkUseCases::issue — a syndic issues a magic link bound to a (scope_kind, scope_id) + recipient user. Returns the clear token ONCE.
  2. MagicLinkUseCases::validate_and_consume — the public /c/{token} endpoint hashes the incoming token, looks it up, validates it, and marks it consumed atomically. Returns the resolved MagicLink so the caller handler can fetch the underlying scope resource.

Security highlights:

  • Clear token is generated inside MagicLink::issue and returned to the handler. It is NEVER logged and NEVER re-fetched from DB.
  • Lookup uses find_by_token_hash(sha256(token)) — a forged token returns None → translated to MagicLinkInvalid (uniform with “unknown token” to defeat enumeration).
  • Single-use enforced by mark_consumed (race-safe UPDATE ... WHERE consumed_at IS NULL at the repository layer).

Structs§

IssuedMagicLinkDto
MagicLinkUseCases