From 4e77f68414c1dd6a906d1d9b6b78916db5c213d5 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 28 Feb 2019 13:58:58 +0300 Subject: [PATCH 1/2] Added `auth_template/0` to DatabaseAuthenticator. --- lib/pleroma/web/auth/database_authenticator.ex | 5 +++++ lib/pleroma/web/auth/pleroma_database_authenticator.ex | 2 ++ lib/pleroma/web/oauth/oauth_controller.ex | 4 +--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/auth/database_authenticator.ex b/lib/pleroma/web/auth/database_authenticator.ex index e78068b03..494f28f23 100644 --- a/lib/pleroma/web/auth/database_authenticator.ex +++ b/lib/pleroma/web/auth/database_authenticator.ex @@ -17,4 +17,9 @@ def get_user(plug), do: implementation().get_user(plug) @callback handle_error(Plug.Conn.t(), any()) :: any() def handle_error(plug, error), do: implementation().handle_error(plug, error) + + @callback auth_template() :: String.t() | nil + def auth_template do + implementation().auth_template() || Pleroma.Config.get(:auth_template, "show.html") + end end diff --git a/lib/pleroma/web/auth/pleroma_database_authenticator.ex b/lib/pleroma/web/auth/pleroma_database_authenticator.ex index 39aa1a586..0780388bc 100644 --- a/lib/pleroma/web/auth/pleroma_database_authenticator.ex +++ b/lib/pleroma/web/auth/pleroma_database_authenticator.ex @@ -23,4 +23,6 @@ def get_user(%Plug.Conn{} = conn) do def handle_error(%Plug.Conn{} = _conn, error) do error end + + def auth_template, do: nil end diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index 5c2b0507c..99346f399 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -25,9 +25,7 @@ def authorize(conn, params) do available_scopes = (app && app.scopes) || [] scopes = oauth_scopes(params, nil) || available_scopes - template = Pleroma.Config.get(:auth_template, "show.html") - - render(conn, template, %{ + render(conn, DatabaseAuthenticator.auth_template(), %{ response_type: params["response_type"], client_id: params["client_id"], available_scopes: available_scopes, From 3281a3f074f8aac6a05a24cc2eee4e5bad2275bd Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Thu, 28 Feb 2019 14:12:41 +0300 Subject: [PATCH 2/2] Renamed *DatabaseAuthenticator to *Authenticator. --- .../auth/{database_authenticator.ex => authenticator.ex} | 6 +++--- ...database_authenticator.ex => pleroma_authenticator.ex} | 4 ++-- lib/pleroma/web/oauth/oauth_controller.ex | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) rename lib/pleroma/web/auth/{database_authenticator.ex => authenticator.ex} (81%) rename lib/pleroma/web/auth/{pleroma_database_authenticator.ex => pleroma_authenticator.ex} (85%) diff --git a/lib/pleroma/web/auth/database_authenticator.ex b/lib/pleroma/web/auth/authenticator.ex similarity index 81% rename from lib/pleroma/web/auth/database_authenticator.ex rename to lib/pleroma/web/auth/authenticator.ex index 494f28f23..82267c595 100644 --- a/lib/pleroma/web/auth/database_authenticator.ex +++ b/lib/pleroma/web/auth/authenticator.ex @@ -2,13 +2,13 @@ # Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -defmodule Pleroma.Web.Auth.DatabaseAuthenticator do +defmodule Pleroma.Web.Auth.Authenticator do alias Pleroma.User def implementation do Pleroma.Config.get( - Pleroma.Web.Auth.DatabaseAuthenticator, - Pleroma.Web.Auth.PleromaDatabaseAuthenticator + Pleroma.Web.Auth.Authenticator, + Pleroma.Web.Auth.PleromaAuthenticator ) end diff --git a/lib/pleroma/web/auth/pleroma_database_authenticator.ex b/lib/pleroma/web/auth/pleroma_authenticator.ex similarity index 85% rename from lib/pleroma/web/auth/pleroma_database_authenticator.ex rename to lib/pleroma/web/auth/pleroma_authenticator.ex index 0780388bc..3cc19af01 100644 --- a/lib/pleroma/web/auth/pleroma_database_authenticator.ex +++ b/lib/pleroma/web/auth/pleroma_authenticator.ex @@ -2,11 +2,11 @@ # Copyright © 2017-2019 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -defmodule Pleroma.Web.Auth.PleromaDatabaseAuthenticator do +defmodule Pleroma.Web.Auth.PleromaAuthenticator do alias Pleroma.User alias Comeonin.Pbkdf2 - @behaviour Pleroma.Web.Auth.DatabaseAuthenticator + @behaviour Pleroma.Web.Auth.Authenticator def get_user(%Plug.Conn{} = conn) do %{"authorization" => %{"name" => name, "password" => password}} = conn.params diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index 99346f399..b16e3b2a7 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do use Pleroma.Web, :controller - alias Pleroma.Web.Auth.DatabaseAuthenticator + alias Pleroma.Web.Auth.Authenticator alias Pleroma.Web.OAuth.Authorization alias Pleroma.Web.OAuth.Token alias Pleroma.Web.OAuth.App @@ -25,7 +25,7 @@ def authorize(conn, params) do available_scopes = (app && app.scopes) || [] scopes = oauth_scopes(params, nil) || available_scopes - render(conn, DatabaseAuthenticator.auth_template(), %{ + render(conn, Authenticator.auth_template(), %{ response_type: params["response_type"], client_id: params["client_id"], available_scopes: available_scopes, @@ -43,7 +43,7 @@ def create_authorization(conn, %{ "redirect_uri" => redirect_uri } = auth_params }) do - with {_, {:ok, %User{} = user}} <- {:get_user, DatabaseAuthenticator.get_user(conn)}, + with {_, {:ok, %User{} = user}} <- {:get_user, Authenticator.get_user(conn)}, %App{} = app <- Repo.get_by(App, client_id: client_id), true <- redirect_uri in String.split(app.redirect_uris), scopes <- oauth_scopes(auth_params, []), @@ -96,7 +96,7 @@ def create_authorization(conn, %{ |> authorize(auth_params) error -> - DatabaseAuthenticator.handle_error(conn, error) + Authenticator.handle_error(conn, error) end end