Current section
Files
Jump to
Current section
Files
lib/vtex_ws_web/authorization/vtex.ex
defmodule VtexWs.Authorization.Vtex do
@moduledoc false
import Plug.Conn
@realm "Basic realm=\"Vtex\""
@authorized_domains ["chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop"]
def init(opts), do: @authorized_domains
def call(conn, opts) do
[origin] = (conn |> get_req_header("origin"))
if Enum.member?(opts, origin) do
conn
else
unauthorized(conn)
end
end
defp unauthorized(conn) do
conn
|> put_resp_header("www-authenticate", @realm)
|> send_resp(401, "unauthorized")
|> halt()
end
end