之间有什么http_basic_authenticate_with和authenticate_or_request_with_http_basic区别?

问题描述 投票:18回答:1

是什么区别

http_basic_authenticate_with()

authenticate_or_request_with_http_basic()

方法?

感谢您的完整的解释。

authentication ruby-on-rails-3.2
1个回答
22
投票

从我可以从docs了解,http_basic_authenticate_with作为它接受一个名称和密码,如前过滤器

http_basic_authenticate_with :name => "dhh", :password => "secret", :except => :index

而authenticate_or_request_with_http_basic接受块允许你插入一些代码,以确定他们是否应该被验证(documentation)。例如。

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
© www.soinside.com 2019 - 2024. All rights reserved.