Implement access token authentication

Add whoami endpoint
This commit is contained in:
Pim Kunis 2021-06-26 00:29:33 +02:00
parent d81a42bf8a
commit dac1a429b9
8 changed files with 96 additions and 4 deletions

View file

@ -1,6 +1,10 @@
defmodule MatrixServerWeb.AccountController do
use MatrixServerWeb, :controller
import MatrixServer, only: [get_mxid: 1]
alias MatrixServer.Account
alias Plug.Conn
def available(conn, params) do
localpart = Map.get(params, "username", "")
@ -21,4 +25,12 @@ defmodule MatrixServerWeb.AccountController do
|> put_status(status)
|> json(data)
end
def whoami(%Conn{assigns: %{account: %Account{localpart: localpart}}} = conn, _params) do
data = %{user_id: get_mxid(localpart)}
conn
|> put_status(200)
|> json(data)
end
end