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

@@ -9,6 +9,7 @@ defmodule Mobilizon.Web.AuthController do
plug(Ueberauth)
@spec request(Plug.Conn.t(), map()) :: Plug.Conn.t()
def request(conn, %{"provider" => provider_name} = _params) do
case provider_config(provider_name) do
{:ok, provider_config} ->
@@ -20,6 +21,7 @@ defmodule Mobilizon.Web.AuthController do
end
end
@spec callback(Plug.Conn.t(), map()) :: Plug.Conn.t() | {:error, any()}
def callback(
%{assigns: %{ueberauth_failure: fails}} = conn,
%{"provider" => provider} = _params
@@ -85,6 +87,7 @@ defmodule Mobilizon.Web.AuthController do
# Github only give public emails as part of the user profile,
# so we explicitely request all user emails and filter on the primary one
@spec email_from_ueberauth(Ueberauth.Auth.t()) :: String.t() | nil
defp email_from_ueberauth(%Ueberauth.Auth{
strategy: Ueberauth.Strategy.Github,
extra: %Ueberauth.Auth.Extra{raw_info: %{user: %{"emails" => emails}}}
@@ -100,6 +103,7 @@ defmodule Mobilizon.Web.AuthController do
defp email_from_ueberauth(_), do: nil
@spec provider_config(String.t()) :: {:ok, any()} | {:error, :not_supported | :unknown_error}
defp provider_config(provider_name) do
with ueberauth when is_list(ueberauth) <- Application.get_env(:ueberauth, Ueberauth),
providers when is_list(providers) <- Keyword.get(ueberauth, :providers),