Authex v0.3.1 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
key() View Source
t()
View Source
t() :: module() | false
t() :: module() | false
Link to this section Callbacks
delete(key)
View Source
delete(key()) :: :ok | :error
delete(key()) :: :ok | :error
Deletes a binary key from the repo.
Returns :ok
on success, or :error
on error.
exists?(key) View Source
Checks if a binary key exists in the repo.
Returns a boolean, or :error
init(config) View Source
A callback executed when the repo process starts.
This should be used to dynamically set any config during runtime.
Returns {:ok, config}
insert(key)
View Source
insert(key()) :: :ok | :error
insert(key()) :: :ok | :error
Inserts a binary key into the repo.
Returns :ok
on success, or :error
on error.
start_link(config)
View Source
start_link(config :: Keyword.t()) :: GenServer.on_start()
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.