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 :admin scope, and
  • database-backed scoped tokens (see Syntropy.Persistence.ApiToken), stored as SHA-256 digests with a read, write, or admin scope.

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

scope()

@type scope() :: :read | :write | :admin

validation_error()

@type validation_error() ::
  :missing_token | :invalid_token | {:insufficient_scope, scope()}

validation_result()

@type validation_result() :: {:ok, scope()} | {:error, validation_error()}

Functions

error_message(arg1)

@spec error_message(validation_error()) :: String.t()

hash_token(plaintext)

@spec hash_token(String.t()) :: String.t()

required?()

@spec required?() :: boolean()

scope_allows?(scope, required_scope)

@spec scope_allows?(scope(), scope()) :: boolean()

token()

@spec token() :: String.t() | nil

validate_conn(conn, required_scope)

@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).

validate_socket(params)

@spec validate_socket(map()) :: validation_result()