What is the difference between http_basic_authenticate_with AND authenticate_or_request_with_http_basic?

半世苍凉 提交于 2019-11-30 08:14:22
chrisbulmer

From what I can understand from the docs, http_basic_authenticate_with acts as a before filter which accepts a name and password such as

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

Whereas authenticate_or_request_with_http_basic accepts a block allowing for you to insert some code to determine whether they should be authenticated (documentation). E.g.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!