two_factor_pam_authenticatable.rb 800 B

12345678910111213141516171819202122232425262728293031
  1. # frozen_string_literal: true
  2. require 'devise/strategies/base'
  3. module Devise
  4. module Strategies
  5. class TwoFactorPamAuthenticatable < Base
  6. def valid?
  7. valid_params? && mapping.to.respond_to?(:authenticate_with_pam)
  8. end
  9. def authenticate!
  10. resource = mapping.to.authenticate_with_pam(params[scope])
  11. if resource && !resource.otp_required_for_login?
  12. success!(resource)
  13. else
  14. fail(:invalid) # rubocop:disable Style/SignalException -- method is from Warden::Strategies::Base
  15. end
  16. end
  17. protected
  18. def valid_params?
  19. params[scope] && params[scope][:password].present?
  20. end
  21. end
  22. end
  23. end
  24. Warden::Strategies.add(:two_factor_pam_authenticatable, Devise::Strategies::TwoFactorPamAuthenticatable)