two_factor_ldap_authenticatable.rb 741 B

1234567891011121314151617181920212223242526272829303132
  1. # frozen_string_literal: true
  2. require 'net/ldap'
  3. require 'devise/strategies/base'
  4. module Devise
  5. module Strategies
  6. class TwoFactorLdapAuthenticatable < Base
  7. def valid?
  8. valid_params? && mapping.to.respond_to?(:authenticate_with_ldap)
  9. end
  10. def authenticate!
  11. resource = mapping.to.authenticate_with_ldap(params[scope])
  12. if resource && !resource.otp_required_for_login?
  13. success!(resource)
  14. else
  15. fail(:invalid)
  16. end
  17. end
  18. protected
  19. def valid_params?
  20. params[scope] && params[scope][:password].present?
  21. end
  22. end
  23. end
  24. end
  25. Warden::Strategies.add(:two_factor_ldap_authenticatable, Devise::Strategies::TwoFactorLdapAuthenticatable)