about summary refs log tree commit diff
path: root/config/initializers/doorkeeper.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2020-01-03 05:35:46 +0100
committerGitHub <noreply@github.com>2020-01-03 05:35:46 +0100
commit59c697a30cae2d50e5be2dd273e5c3956b2a2d6e (patch)
tree6cb5ada98eedba40a0b0a27a65982df02cd04c39 /config/initializers/doorkeeper.rb
parent47293419034ed64e5d75e8f60621824762edb967 (diff)
Fix resource_owner_from_credentials in Doorkeeper initializer (#12743)
- Nil error when e-mail not found
- LDAP authentication used in place of PAM authentication
Diffstat (limited to 'config/initializers/doorkeeper.rb')
-rw-r--r--config/initializers/doorkeeper.rb13
1 files changed, 4 insertions, 9 deletions
diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb
index 7784bec62..e03380cec 100644
--- a/config/initializers/doorkeeper.rb
+++ b/config/initializers/doorkeeper.rb
@@ -8,20 +8,15 @@ Doorkeeper.configure do
   end
 
   resource_owner_from_credentials do |_routes|
-    if Devise.ldap_authentication
-      user = User.authenticate_with_ldap({ :email => request.params[:username], :password => request.params[:password] })
-    end
-
-    if Devise.pam_authentication
-      user ||= User.authenticate_with_ldap({ :email => request.params[:username], :password => request.params[:password] })
-    end
+    user   = User.authenticate_with_ldap(email: request.params[:username], password: request.params[:password]) if Devise.ldap_authentication
+    user ||= User.authenticate_with_pam(email: request.params[:username], password: request.params[:password]) if Devise.pam_authentication
 
     if user.nil?
       user = User.find_by(email: request.params[:username])
-      user = nil unless user.valid_password?(request.params[:password])
+      user = nil unless user&.valid_password?(request.params[:password])
     end
 
-    user if !user&.otp_required_for_login?
+    user unless user&.otp_required_for_login?
   end
 
   # If you want to restrict access to the web interface for adding oauth authorized applications, you need to declare the block below.