What is the difference between http_basic_authenticate_with AND authenticate_or_request_with_http_basic?

后端 未结 1 332
轻奢々
轻奢々 2020-12-31 01:16

What is the difference between

http_basic_authenticate_with()

and

authenticate_or_request_with_http_basic()
相关标签:
1条回答
  • 2020-12-31 02:16

    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
    
    0 讨论(0)
提交回复
热议问题