Dou*_*las 18 authentication ruby-on-rails-3.2
有什么区别
http_basic_authenticate_with()
和
authenticate_or_request_with_http_basic()
方法?
谢谢你的完整解释.
chr*_*mer 22
从我可以从文档中理解,http_basic_authenticate_with作为一个接受名称和密码的前过滤器,如
http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index
而authenticate_or_request_with_http_basic接受一个块,允许您插入一些代码以确定是否应对其进行身份验证(文档).例如
before_filter :authenticate
def authenticate
  authenticate_or_request_with_http_basic('Administration') do |username, password|
    ActiveSupport::SecurityUtils.secure_compare(username, "admin") &&
    ActiveSupport::SecurityUtils.secure_compare(password, "password")
  end
end