Authex v0.3.0 Authex.Repo behaviour View Source

Defines a verification repo.

This allows for the creation of persistent storage for blacklists and banlists. Blacklists are used to block usage of a token by its :jti key. Banlists are used to block usage of a token by its :sub key.

defmodule MyApp.Auth.Banlist do
  use Authex.Repo

  @impl Authex.Repo
  def start_link(config) do
    # Start the repo process if required.
  end

  @impl Authex.Repo
  def init(config) do
    # Perform any dynamic config.
  end

  @impl Authex.Repo
  def exists?(key) do
    # Check if the key exists in the repo.
  end

  @impl Authex.Repo
  def insert(key) do
    # Insert the key in the repo.
  end

  @impl Authex.Repo
  def delete(key) do
    # Delete the key from the repo.
  end
end

Please be aware of the performance penalty that may be incurred if using blacklists and banlists during the auth verification process. This will largely depend on the storage medium used.

Link to this section Summary

Callbacks

Deletes a binary key from the repo

Checks if a binary key exists in the repo

A callback executed when the repo process starts

Inserts a binary key into the repo

Starts the repo process

Link to this section Types

Link to this section Callbacks

Link to this callback

delete(key) View Source
delete(key()) :: :ok | :error

Deletes a binary key from the repo.

Returns :ok on success, or :error on error.

Link to this callback

exists?(key) View Source
exists?(key()) :: boolean() | :error

Checks if a binary key exists in the repo.

Returns a boolean, or :error

Link to this callback

init(config) View Source
init(config :: Keyword.t()) :: {:ok, Keyword.t()}

A callback executed when the repo process starts.

This should be used to dynamically set any config during runtime.

Returns {:ok, config}

Link to this callback

insert(key) View Source
insert(key()) :: :ok | :error

Inserts a binary key into the repo.

Returns :ok on success, or :error on error.

Link to this callback

start_link(config) View Source
start_link(config :: Keyword.t()) :: GenServer.on_start()

Starts the repo process.

Returns {:ok, pid} on success.

Returns {:error, {:already_started, pid}} if the repo process is already started or {:error, term} in case anything else goes wrong.