You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
741 B

  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)