aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/oauth/oauth_controller.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pleroma/web/oauth/oauth_controller.ex')
-rw-r--r--lib/pleroma/web/oauth/oauth_controller.ex27
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex
index 7c1a3adbd..654beb2c4 100644
--- a/lib/pleroma/web/oauth/oauth_controller.ex
+++ b/lib/pleroma/web/oauth/oauth_controller.ex
@@ -130,8 +130,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
%{"grant_type" => "password", "username" => name, "password" => password} = params
) do
with %App{} = app <- get_app_from_request(conn, params),
- %User{} = user <- User.get_by_nickname_or_email(name),
- true <- Pbkdf2.checkpw(password, user.password_hash),
+ %User{} = user <- get_user(name, password),
{:auth_active, true} <- {:auth_active, User.auth_active?(user)},
scopes <- oauth_scopes(params, app.scopes),
[] <- scopes -- app.scopes,
@@ -215,4 +214,28 @@ defmodule Pleroma.Web.OAuth.OAuthController do
nil
end
end
+
+ defp get_user(name, password) do
+ if Pleroma.Config.get([:ldap, :enabled]) do
+ case Pleroma.LDAP.get_user(name, password) do
+ %User{} = user ->
+ user
+
+ {:error, {:ldap_connection_error, _}} ->
+ # When LDAP is unavailable, try default login
+ with %User{} = user <- User.get_by_nickname_or_email(name),
+ true <- Pbkdf2.checkpw(password, user.password_hash) do
+ user
+ end
+
+ error ->
+ error
+ end
+ else
+ with %User{} = user <- User.get_by_nickname_or_email(name),
+ true <- Pbkdf2.checkpw(password, user.password_hash) do
+ user
+ end
+ end
+ end
end