Wiztchta.Store behaviour (wiztchta v0.1.0)

Copy Markdown View Source

Behaviour for replay protection: remembers which challenge tokens were already submitted until they expire.

The default, Wiztchta.Store.ETS, is started automatically and keeps used ids in memory on the local node. In a multi-node cluster a token could be replayed once per node; plug in a shared store (Redis, Nebulex, a database...) to prevent that:

config :wiztchta, store: MyApp.WiztchtaRedisStore

Set store: nil to disable replay protection.

Summary

Callbacks

Atomically marks id as used until expires_at (unix seconds).

Callbacks

consume(id, expires_at, opts)

@callback consume(id :: String.t(), expires_at :: integer(), opts :: keyword()) ::
  :ok | {:error, :already_used}

Atomically marks id as used until expires_at (unix seconds).

Must return {:error, :already_used} if id was already consumed.