Phauxth v1.1.0 Phauxth.Authenticate.Base View Source
Base module for authentication.
This is used by Phauxth.Authenticate and Phauxth.Remember. It can also be used to produce a custom authentication module, as outlined below.
Custom authentication modules
One example of a custom authentication module is provided by the Phauxth.Remember module, which uses this base module to provide the ‘remember me’ functionality.
Graphql authentication
The following module is another example of how this Base module can be extended, this time to provide authentication for absinthe-elixir:
defmodule AbsintheAuthenticate do
use Phauxth.Authenticate.Base
import Plug.Conn
def set_user(user, conn) do
put_private(conn, :absinthe, %{token: %{current_user: user}})
end
end
And in the router.ex
file, call this plug in the pipeline you
want to authenticate (setting the method to :token).
pipeline :api do
plug :accepts, ["json"]
plug AbsintheAuthenticate, method: :token
end
Custom session / token implementations
This module uses Plug sessions or Phauxth tokens (based on Phoenix.Token)
by default. To use custom sessions or tokens, you need to create your
own custom Authenticate module and override the check_session
or
check_token
function.