Move LDAP code to LDAPAuthenticator. Use Authenticator for token_exchange with grant_type as well

This commit is contained in:
link0ff 2019-03-03 21:20:36 +02:00
commit 88a672fe88
4 changed files with 55 additions and 32 deletions

View file

@ -9,7 +9,14 @@ defmodule Pleroma.Web.Auth.PleromaAuthenticator do
@behaviour Pleroma.Web.Auth.Authenticator
def get_user(%Plug.Conn{} = conn) do
%{"authorization" => %{"name" => name, "password" => password}} = conn.params
{name, password} =
case conn.params do
%{"authorization" => %{"name" => name, "password" => password}} ->
{name, password}
%{"grant_type" => "password", "username" => name, "password" => password} ->
{name, password}
end
with {_, %User{} = user} <- {:user, User.get_by_nickname_or_email(name)},
{_, true} <- {:checkpw, Pbkdf2.checkpw(password, user.password_hash)} do