Packages

Adds authentication and authorization to a Phoenix project. A user can login with a username and password held in the DB or against an LDAP server.

Current section

Files

Jump to
simple_auth lib simple_auth.ex
Raw

lib/simple_auth.ex

defmodule SimpleAuth do
use Application
# The application is needed in case the UserSession.Memory is used. As the OTP behaviour
# for the Application start callback requires the `{:ok, pid}` to be returned, the supervisor
# is still started even if it has nothing to supervise.
defp user_session_api(), do: Application.get_env(:simple_auth, :user_session_api)
def start(_type, _args) do
import Supervisor.Spec
children =
case user_session_api() do
SimpleAuth.UserSession.Memory ->
[worker(SimpleAuth.UserSession.Memory, [])]
_ ->
[]
end
opts = [strategy: :one_for_one, name: SimpleAuth.Supervisor]
Supervisor.start_link(children, opts)
end
end