闭社主体 forked from https://github.com/tootsuite/mastodon
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.

31 lines
717 B

  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)
  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)