summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre de Lacroix <pierre@pdelacroix.com>2020-12-19 16:45:08 +0100
committerPierre de Lacroix <pierre@pdelacroix.com>2020-12-19 16:45:08 +0100
commit716e13ec40a6e77e1caca2fb79928f83343c0d73 (patch)
tree3a0e4f3671df9aacbf00b5877f9a801340a3bdc0
parentMerge branch 'repo_setup' into 'master' (diff)
allow runtime configuration of homserver token
-rw-r--r--lib/matrix_app_service/client.ex4
-rw-r--r--lib/matrix_app_service_web/auth_plug.ex29
2 files changed, 24 insertions, 9 deletions
diff --git a/lib/matrix_app_service/client.ex b/lib/matrix_app_service/client.ex
index cec1046..08407dc 100644
--- a/lib/matrix_app_service/client.ex
+++ b/lib/matrix_app_service/client.ex
@@ -115,4 +115,8 @@ defmodule MatrixAppService.Client do
client(client_options)
|> Polyjuice.Client.LowLevel.register(opts)
end
+
+ defdelegate get_data(client, id, key), to: Polyjuice.Client.Account
+ defdelegate get_profile(client, id), to: Polyjuice.Client.Profile
+ defdelegate modify_display(client, id, name), to: Polyjuice.Client.Profile
end
diff --git a/lib/matrix_app_service_web/auth_plug.ex b/lib/matrix_app_service_web/auth_plug.ex
index 19f8c21..be38fb0 100644
--- a/lib/matrix_app_service_web/auth_plug.ex
+++ b/lib/matrix_app_service_web/auth_plug.ex
@@ -11,21 +11,18 @@ defmodule MatrixAppServiceWeb.AuthPlug do
@doc false
@impl Plug
- def init(opts) do
- opts
+ def init(homeserver_token) do
+ homeserver_token
end
@doc false
@impl Plug
- def call(%Plug.Conn{params: %{"access_token" => access_token}} = conn, homeserver_token)
- when access_token == homeserver_token do
- conn
+ def call(%Plug.Conn{params: %{"access_token" => access_token}} = conn, homeserver_token) when is_binary(homeserver_token) do
+ verify_access_token(conn, homeserver_token)
end
- def call(%Plug.Conn{params: %{"access_token" => _access_token}} = conn, _homeserver_token) do
- Logger.warn("Received invalid homeserver token")
-
- respond_error(conn, 403)
+ def call(%Plug.Conn{params: %{"access_token" => access_token}} = conn, homeserver_token) when is_function(homeserver_token, 0) do
+ verify_access_token(conn, homeserver_token.())
end
def call(conn, _opts) do
@@ -34,6 +31,20 @@ defmodule MatrixAppServiceWeb.AuthPlug do
respond_error(conn, 401)
end
+ defp verify_access_token(
+ %Plug.Conn{params: %{"access_token" => access_token}} = conn,
+ homeserver_token
+ )
+ when access_token == homeserver_token do
+ conn
+ end
+
+ defp verify_access_token(conn, _homeserver_token) do
+ Logger.warn("Received invalid homeserver token")
+
+ respond_error(conn, 403)
+ end
+
defp respond_error(conn, error_code) do
conn
|> put_status(error_code)