authenticator v1.0.0 Authenticator behaviour
Generates a module for authenticating requests based on the Plug.Conn.
Example
defmodule MyAppWeb.Authentication do
use Authenticator, fallback: MyAppWeb.FallbackController
alias MyApp.Repo
alias MyApp.Accounts.User
@impl true
def tokenize(user) do
{:ok, to_string(user.id)}
end
@impl true
def authenticate(user_id) do
case Repo.get(User, user_id) do
nil ->
{:error, :unauthenticated}
user ->
{:ok, user}
end
end
end
Link to this section Summary
Link to this section Types
Link to this section Callbacks
Link to this callback
authenticate(token)
Link to this callback
tokenize(resource)