SyntropyWeb.ApiAuth
(syntropy v0.2.0)
Copy Markdown
Runtime auth policy for Syntropy's external REST and channel surface.
Two token kinds are accepted:
- the environment root token (
SYNTROPY_API_TOKEN), which carries the:adminscope, and - database-backed scoped tokens (see
Syntropy.Persistence.ApiToken), stored as SHA-256 digests with aread,write, oradminscope.
Scopes are hierarchical: admin > write > read.
Summary
Functions
Validates the request bearer token and enforces the scope class required by
the route (:read, :write, or :admin).
Types
@type scope() :: :read | :write | :admin
@type validation_error() :: :missing_token | :invalid_token | {:insufficient_scope, scope()}
@type validation_result() :: {:ok, scope()} | {:error, validation_error()}
Functions
@spec error_message(validation_error()) :: String.t()
@spec required?() :: boolean()
@spec token() :: String.t() | nil
@spec validate_conn(Plug.Conn.t(), scope()) :: validation_result()
Validates the request bearer token and enforces the scope class required by
the route (:read, :write, or :admin).
@spec validate_socket(map()) :: validation_result()