aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/oauth/oauth_controller.ex
diff options
context:
space:
mode:
authorlink0ff <juri@linkov.net>2019-02-22 15:03:43 +0200
committerlink0ff <juri@linkov.net>2019-02-22 15:03:43 +0200
commite278d470232f4e8081bbbe358137400074673e75 (patch)
treea418de7b436981011da1c592bcc3d9fab15ddd29 /lib/pleroma/web/oauth/oauth_controller.ex
parent5a4e2905fecfd21cf92f6b2844f15f5ee84b33f5 (diff)
downloadpleroma-e278d470232f4e8081bbbe358137400074673e75.tar.gz
OpenLDAP support
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