本文介绍了http_basic_authenticate_with和authenticate_or_request_with_http_basic有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两者之间有什么区别

http_basic_authenticate_with()

authenticate_or_request_with_http_basic()

方法?

感谢您的完整解释.

推荐答案

据我从 docs http_basic_authenticate_with用作接受名称和密码(例如

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

而authenticate_or_request_with_http_basic接受一个块,允许您插入一些代码以确定是否应对其进行身份验证(文档).例如

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

这篇关于http_basic_authenticate_with和authenticate_or_request_with_http_basic有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 08:33