Refactor Mobilizon.Federation.ActivityPub and add typespecs

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-09-28 19:40:37 +02:00
parent 41f086e2c9
commit b5d9b82bdd
125 changed files with 2497 additions and 1673 deletions

View File

@@ -5,6 +5,7 @@ defmodule Mobilizon.Web.Auth.ErrorHandler do
import Plug.Conn
# sobelow_skip ["XSS.SendResp"]
@spec auth_error(Plug.Conn.t(), any(), any()) :: Plug.Conn.t()
def auth_error(conn, {type, _reason}, _opts) do
body = Jason.encode!(%{message: to_string(type)})
send_resp(conn, 401, body)

View File

@@ -15,6 +15,7 @@ defmodule Mobilizon.Web.Auth.Guardian do
require Logger
@spec subject_for_token(any(), any()) :: {:ok, String.t()} | {:error, :unknown_resource}
def subject_for_token(%User{} = user, _claims) do
{:ok, "User:" <> to_string(user.id)}
end
@@ -45,30 +46,35 @@ defmodule Mobilizon.Web.Auth.Guardian do
{:error, :no_claims}
end
@spec after_encode_and_sign(any(), any(), any(), any()) :: {:ok, String.t()}
def after_encode_and_sign(resource, claims, token, _options) do
with {:ok, _} <- Guardian.DB.after_encode_and_sign(resource, claims["typ"], claims, token) do
{:ok, token}
end
end
@spec on_verify(any(), any(), any()) :: {:ok, any()}
def on_verify(claims, token, _options) do
with {:ok, _} <- Guardian.DB.on_verify(claims, token) do
{:ok, claims}
end
end
@spec on_revoke(any(), any(), any()) :: {:ok, any()}
def on_revoke(claims, token, _options) do
with {:ok, _} <- Guardian.DB.on_revoke(claims, token) do
{:ok, claims}
end
end
@spec on_refresh({any(), any()}, {any(), any()}, any()) :: {:ok, {any(), any()}, {any(), any()}}
def on_refresh({old_token, old_claims}, {new_token, new_claims}, _options) do
with {:ok, _, _} <- Guardian.DB.on_refresh({old_token, old_claims}, {new_token, new_claims}) do
{:ok, {old_token, old_claims}, {new_token, new_claims}}
end
end
@spec on_exchange(any(), any(), any()) :: {:ok, {any(), any()}, {any(), any()}}
def on_exchange(old_stuff, new_stuff, options), do: on_refresh(old_stuff, new_stuff, options)
# def build_claims(claims, _resource, opts) do