View Source Antikythera.Plug.BasicAuthentication (antikythera v0.5.1)

Plug to restrict access to controller action by basic authentication.

Usage

Static username/password: using gear config

The following line installs a plug that checks username/password in incoming requests against "BASIC_AUTHENTICATION_ID" and "BASIC_AUTHENTICATION_PW" in your gear's gear config.

plug Antikythera.Plug.BasicAuthentication, :check_with_config, []

Dynamic username/password: using module-function pair.

In the following case you can check the username/password pair with arbitrary logic by the specified function.

plug Antikythera.Plug.BasicAuthentication, :check_with_fun, [mod: YourGear.AuthModule, fun: :function_name]

The given function (YourGear.AuthModule.function_name/3 in this case) must have the following type signature:

  • receives (1) a Antikythera.Conn.t, (2) username, and (3) password
  • returns (1) {:ok, Antikythera.Conn.t} if successfully authenticated, (2) :error otherwise

Summary

Functions

Link to this function

check_with_config(conn, opts)

View Source
@spec check_with_config(Antikythera.Conn.t(), any()) :: Antikythera.Conn.t()
Link to this function

check_with_fun(conn, opts)

View Source
@spec check_with_fun(Antikythera.Conn.t(), [{:mod | :fun, atom()}]) ::
  Antikythera.Conn.t()