View Source CsrfPlus.Store.Behaviour behaviour (CsrfPlus v0.2.0)
Defines the behaviour for a store.
Summary
Callbacks
Returns all the accesses in the store.
A function to return the user access struct for a given connection and raw access map.
Deletes an access from the store by its access_id
.
May delete all the tokens in the store that had expired. Other option, is to flag them as expired.
Given an access_id
, returns the access associated with it.
Puts an access in the store.
Callbacks
@callback all_accesses() :: [CsrfPlus.UserAccess.t()]
Returns all the accesses in the store.
@callback conn_to_access( conn :: Plug.Conn.t(), raw_access :: %{access_id: String.t(), token: String.t()} ) :: CsrfPlus.UserAccess.t()
A function to return the user access struct for a given connection and raw access map.
Params
conn
- The connection struct.raw_access
- A map with the required access information.
Raw Access
:access_id
- The id that identifies the access.:token
- The access token.
@callback delete_access(access_id :: String.t()) :: {:ok, CsrfPlus.UserAccess.t()} | {:error, term()}
Deletes an access from the store by its access_id
.
Returns
{:ok, user_access}
if the access was successfully deleted.user_access
is the access that was deleted.{:error, reason}
if it was not possible for anyreason
.
@callback delete_dead_accesses(max_age :: non_neg_integer()) :: :ok | {:error, term()}
May delete all the tokens in the store that had expired. Other option, is to flag them as expired.
Returns
:ok
in case of success or {:error, reason}
otherwise.
@callback get_access(access_id :: String.t()) :: CsrfPlus.UserAccess.t() | nil
Given an access_id
, returns the access associated with it.
@callback put_access(user_access :: CsrfPlus.UserAccess.t()) :: {:ok, CsrfPlus.UserAccess.t()} | {:error, term()}
Puts an access in the store.
Returns
{:ok, UserAccess.t()}
if the access was successfully store{:error, reason}
if it was not possible for anyreason
.