Current section
Files
Jump to
Current section
Files
lib/aesir/context/authorization.ex
defmodule Aesir.Context.Authorization do
alias Aesir.Context
import Plug.Conn, only: [get_req_header: 2]
@behaviour Context
@impl Context
def context(context, conn) do
with ["Aesir " <> data] <- get_req_header(conn, "authorization"),
{:ok, authorizations = %{}} <- Jason.decode(data, keys: :atoms) do
Enum.reduce(authorizations, context, fn {auth, value}, c ->
Context.add_auth(c, auth, value)
end)
else
_ -> context
end
end
end