diff options
author | Pierre de Lacroix <pierre@pdelacroix.com> | 2020-09-18 11:49:27 +0000 |
---|---|---|
committer | Pierre de Lacroix <pierre@pdelacroix.com> | 2020-09-18 11:49:27 +0000 |
commit | 2ba17e75c1aa5a4de08299cd8c9281aa45f5ce2c (patch) | |
tree | 4b85c4054ee65594d842c917d3c75aba7dcd5b8f /lib | |
parent | run mix format (diff) | |
parent | added test (diff) |
Merge branch 'test/matrix_app_auth_plug' into 'master'
added test for the authplug
See merge request kazarma/matrix_app_service.ex!4
Diffstat (limited to 'lib')
-rw-r--r-- | lib/matrix_app_service/phoenix/router.ex | 2 | ||||
-rw-r--r-- | lib/matrix_app_service_web/auth_plug.ex (renamed from lib/matrix_app_service/auth_plug.ex) | 15 |
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/matrix_app_service/phoenix/router.ex b/lib/matrix_app_service/phoenix/router.ex index 2a4aba6..b3e6c8f 100644 --- a/lib/matrix_app_service/phoenix/router.ex +++ b/lib/matrix_app_service/phoenix/router.ex @@ -3,7 +3,7 @@ defmodule MatrixAppService.Phoenix.Router do quote do pipeline :matrix_api do plug :accepts, ["json"] - plug MatrixAppService.AuthPlug + plug MatrixAppServiceWeb.AuthPlug end path = Application.compile_env(:matrix_app_service, :path, "/") diff --git a/lib/matrix_app_service/auth_plug.ex b/lib/matrix_app_service_web/auth_plug.ex index 8adbc91..2d2ae23 100644 --- a/lib/matrix_app_service/auth_plug.ex +++ b/lib/matrix_app_service_web/auth_plug.ex @@ -1,15 +1,24 @@ -defmodule MatrixAppService.AuthPlug do +defmodule MatrixAppServiceWeb.AuthPlug do + @moduledoc """ + This Plug implements the Application Service authorization, + as described here: + + https://matrix.org/docs/spec/application_service/r0.1.2#authorization + """ + @behaviour Plug import Plug.Conn require Logger + @doc false @impl Plug def init(opts) do opts end + @doc false @impl Plug - def call(%Plug.Conn{params: %{"access_token" => hs_token}} = conn, _) do + def call(%Plug.Conn{params: %{"access_token" => hs_token}} = conn, _opts) do config_hs_token = Application.fetch_env!(:matrix_app_service, :homeserver_token) with ^config_hs_token <- hs_token do @@ -21,7 +30,7 @@ defmodule MatrixAppService.AuthPlug do end end - def call(conn, _config_hs_token) do + def call(conn, _opts) do Logger.warn("No homeserver token provided") respond_error(conn, 401) end |