diff options
-rw-r--r-- | lib/matrix_app_service_web/auth_plug.ex | 4 | ||||
-rw-r--r-- | lib/matrix_app_service_web/set_config_plug.ex | 22 |
2 files changed, 19 insertions, 7 deletions
diff --git a/lib/matrix_app_service_web/auth_plug.ex b/lib/matrix_app_service_web/auth_plug.ex index 4a0b386..b3965ad 100644 --- a/lib/matrix_app_service_web/auth_plug.ex +++ b/lib/matrix_app_service_web/auth_plug.ex @@ -27,6 +27,10 @@ defmodule MatrixAppServiceWeb.AuthPlug do verify_access_token(conn, homeserver_token.()) end + def call(%Plug.Conn{params: %{"access_token" => _access_token}} = conn, :config) do + verify_access_token(conn, Application.fetch_env!(:matrix_app_service, :app_service)[:homeserver_token]) + end + def call(conn, _opts) do Logger.warn("No homeserver token provided") diff --git a/lib/matrix_app_service_web/set_config_plug.ex b/lib/matrix_app_service_web/set_config_plug.ex index a7fdf89..b8dd9fa 100644 --- a/lib/matrix_app_service_web/set_config_plug.ex +++ b/lib/matrix_app_service_web/set_config_plug.ex @@ -17,12 +17,20 @@ defmodule MatrixAppServiceWeb.SetConfigPlug do @impl Plug def call(conn, opts) do conn - |> put_private(:transaction_adapter, Keyword.fetch!(opts, :transaction_adapter)) - |> put_private(:room_adapter, Keyword.fetch!(opts, :room_adapter)) - |> put_private(:user_adapter, Keyword.fetch!(opts, :user_adapter)) - |> put_private(:homeserver_token, Keyword.fetch!(opts, :homeserver_token)) - |> put_private(:access_token, Keyword.fetch!(opts, :access_token)) - |> put_private(:base_url, Keyword.fetch!(opts, :base_url)) - |> put_private(:path, Keyword.fetch!(opts, :path)) + |> put_config(:transaction_adapter, Keyword.fetch!(opts, :transaction_adapter)) + |> put_config(:room_adapter, Keyword.fetch!(opts, :room_adapter)) + |> put_config(:user_adapter, Keyword.fetch!(opts, :user_adapter)) + |> put_config(:homeserver_token, Keyword.fetch!(opts, :homeserver_token)) + |> put_config(:access_token, Keyword.fetch!(opts, :access_token)) + |> put_config(:base_url, Keyword.fetch!(opts, :base_url)) + |> put_config(:path, Keyword.fetch!(opts, :path)) + end + + defp put_config(conn, key, :config) do + value = Application.fetch_env!(:matrix_app_service, :app_service)[:key] + put_private(conn, key, value) + end + defp put_config(conn, key, value) do + put_private(conn, key, value) end end |