Packages
A Fair Source multi-agent runtime with deterministic agent scoring and replayable run history.
Retired package: Deprecated - superseded — operator console moved to the Syntropy app
Current section
Files
Jump to
Current section
Files
lib/syntropy_web/plugs/api_auth.ex
defmodule SyntropyWeb.Plugs.ApiAuth do
@moduledoc """
Enforces Syntropy external API auth when token auth is enabled.
"""
import Plug.Conn
import Phoenix.Controller, only: [json: 2]
alias SyntropyWeb.ApiAuth
@spec init(term()) :: term()
def init(opts), do: opts
@spec call(Plug.Conn.t(), term()) :: Plug.Conn.t()
def call(conn, _opts) do
case ApiAuth.validate_conn(conn) do
:ok ->
conn
{:error, reason} ->
conn
|> put_status(:unauthorized)
|> json(%{
error: %{
code: "unauthorized",
message: ApiAuth.error_message(reason)
}
})
|> halt()
end
end
end