]> cat aescling's git repositories - mastodon.git/blob - lib/devise/two_factor_ldap_authenticatable.rb
Fix authentication before 2FA challenge (#11943)
[mastodon.git] / lib / devise / two_factor_ldap_authenticatable.rb
1 # frozen_string_literal: true
2
3 require 'net/ldap'
4 require 'devise/strategies/base'
5
6 module Devise
7 module Strategies
8 class TwoFactorLdapAuthenticatable < Base
9 def valid?
10 valid_params? && mapping.to.respond_to?(:authenticate_with_ldap)
11 end
12
13 def authenticate!
14 resource = mapping.to.authenticate_with_ldap(params[scope])
15
16 if resource && !resource.otp_required_for_login?
17 success!(resource)
18 else
19 fail(:invalid)
20 end
21 end
22
23 protected
24
25 def valid_params?
26 params[scope] && params[scope][:password].present?
27 end
28 end
29 end
30 end
31
32 Warden::Strategies.add(:two_factor_ldap_authenticatable, Devise::Strategies::TwoFactorLdapAuthenticatable)
This page took 0.098418 seconds and 6 git commands to generate.