forked from AkkomaGang/akkoma
Merge branch 'customizable_auth' into 'develop'
Authenticator tweaks See merge request pleroma/pleroma!875
This commit is contained in:
commit
a47cc5a2cf
3 changed files with 16 additions and 11 deletions
|
@ -2,13 +2,13 @@
|
||||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.Auth.DatabaseAuthenticator do
|
defmodule Pleroma.Web.Auth.Authenticator do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
def implementation do
|
def implementation do
|
||||||
Pleroma.Config.get(
|
Pleroma.Config.get(
|
||||||
Pleroma.Web.Auth.DatabaseAuthenticator,
|
Pleroma.Web.Auth.Authenticator,
|
||||||
Pleroma.Web.Auth.PleromaDatabaseAuthenticator
|
Pleroma.Web.Auth.PleromaAuthenticator
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,4 +17,9 @@ def get_user(plug), do: implementation().get_user(plug)
|
||||||
|
|
||||||
@callback handle_error(Plug.Conn.t(), any()) :: any()
|
@callback handle_error(Plug.Conn.t(), any()) :: any()
|
||||||
def handle_error(plug, error), do: implementation().handle_error(plug, error)
|
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
|
end
|
|
@ -2,11 +2,11 @@
|
||||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.Auth.PleromaDatabaseAuthenticator do
|
defmodule Pleroma.Web.Auth.PleromaAuthenticator do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Comeonin.Pbkdf2
|
alias Comeonin.Pbkdf2
|
||||||
|
|
||||||
@behaviour Pleroma.Web.Auth.DatabaseAuthenticator
|
@behaviour Pleroma.Web.Auth.Authenticator
|
||||||
|
|
||||||
def get_user(%Plug.Conn{} = conn) do
|
def get_user(%Plug.Conn{} = conn) do
|
||||||
%{"authorization" => %{"name" => name, "password" => password}} = conn.params
|
%{"authorization" => %{"name" => name, "password" => password}} = conn.params
|
||||||
|
@ -23,4 +23,6 @@ def get_user(%Plug.Conn{} = conn) do
|
||||||
def handle_error(%Plug.Conn{} = _conn, error) do
|
def handle_error(%Plug.Conn{} = _conn, error) do
|
||||||
error
|
error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def auth_template, do: nil
|
||||||
end
|
end
|
|
@ -5,7 +5,7 @@
|
||||||
defmodule Pleroma.Web.OAuth.OAuthController do
|
defmodule Pleroma.Web.OAuth.OAuthController do
|
||||||
use Pleroma.Web, :controller
|
use Pleroma.Web, :controller
|
||||||
|
|
||||||
alias Pleroma.Web.Auth.DatabaseAuthenticator
|
alias Pleroma.Web.Auth.Authenticator
|
||||||
alias Pleroma.Web.OAuth.Authorization
|
alias Pleroma.Web.OAuth.Authorization
|
||||||
alias Pleroma.Web.OAuth.Token
|
alias Pleroma.Web.OAuth.Token
|
||||||
alias Pleroma.Web.OAuth.App
|
alias Pleroma.Web.OAuth.App
|
||||||
|
@ -25,9 +25,7 @@ def authorize(conn, params) do
|
||||||
available_scopes = (app && app.scopes) || []
|
available_scopes = (app && app.scopes) || []
|
||||||
scopes = oauth_scopes(params, nil) || available_scopes
|
scopes = oauth_scopes(params, nil) || available_scopes
|
||||||
|
|
||||||
template = Pleroma.Config.get(:auth_template, "show.html")
|
render(conn, Authenticator.auth_template(), %{
|
||||||
|
|
||||||
render(conn, template, %{
|
|
||||||
response_type: params["response_type"],
|
response_type: params["response_type"],
|
||||||
client_id: params["client_id"],
|
client_id: params["client_id"],
|
||||||
available_scopes: available_scopes,
|
available_scopes: available_scopes,
|
||||||
|
@ -45,7 +43,7 @@ def create_authorization(conn, %{
|
||||||
"redirect_uri" => redirect_uri
|
"redirect_uri" => redirect_uri
|
||||||
} = auth_params
|
} = auth_params
|
||||||
}) do
|
}) 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),
|
%App{} = app <- Repo.get_by(App, client_id: client_id),
|
||||||
true <- redirect_uri in String.split(app.redirect_uris),
|
true <- redirect_uri in String.split(app.redirect_uris),
|
||||||
scopes <- oauth_scopes(auth_params, []),
|
scopes <- oauth_scopes(auth_params, []),
|
||||||
|
@ -98,7 +96,7 @@ def create_authorization(conn, %{
|
||||||
|> authorize(auth_params)
|
|> authorize(auth_params)
|
||||||
|
|
||||||
error ->
|
error ->
|
||||||
DatabaseAuthenticator.handle_error(conn, error)
|
Authenticator.handle_error(conn, error)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue