[#923] Merge remote-tracking branch 'remotes/upstream/develop' into twitter_oauth
[akkoma] / lib / pleroma / web / auth / authenticator.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Auth.Authenticator do
6 alias Pleroma.User
7
8 def implementation do
9 Pleroma.Config.get(
10 Pleroma.Web.Auth.Authenticator,
11 Pleroma.Web.Auth.PleromaAuthenticator
12 )
13 end
14
15 @callback get_user(Plug.Conn.t(), Map.t()) :: {:ok, User.t()} | {:error, any()}
16 def get_user(plug, params), do: implementation().get_user(plug, params)
17
18 @callback get_or_create_user_by_oauth(Plug.Conn.t(), Map.t()) ::
19 {:ok, User.t()} | {:error, any()}
20 def get_or_create_user_by_oauth(plug, params),
21 do: implementation().get_or_create_user_by_oauth(plug, params)
22
23 @callback handle_error(Plug.Conn.t(), any()) :: any()
24 def handle_error(plug, error), do: implementation().handle_error(plug, error)
25
26 @callback auth_template() :: String.t() | nil
27 def auth_template do
28 implementation().auth_template() || Pleroma.Config.get(:auth_template, "show.html")
29 end
30 end