Phauxth v0.15.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