http_basic_authenticate_with और authenticate_or_request_with_http_basic के बीच क्या अंतर है?
http_basic_authenticate_with()
और
authenticate_or_request_with_http_basic()
तरीकों के बीच क्या अंतर है?
अपने पूरे स्पष्टीकरण के लिए धन्यवाद।
http_basic_authenticate_with और authenticate_or_request_with_http_basic के बीच क्या अंतर है?
http_basic_authenticate_with()
और
authenticate_or_request_with_http_basic()
तरीकों के बीच क्या अंतर है?
अपने पूरे स्पष्टीकरण के लिए धन्यवाद।
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
(सावधान रहें, इस उदाहरण सुरक्षित नहीं हो सकता। उदाहरण के लिए, वर्तमान में यह असुरक्षित है, क्योंकि यह secure_compare
का उपयोग करता variable_size_secure_compare
के बजाय। एक अधिक सुरक्षित के लिए रेल के वर्तमान संस्करण से ActionController::HttpAuthentication
में http_basic_authenticate_with
की source code देखें उदाहरण।)
कैपिबरा के साथ इसका परीक्षण करने के लिए, http://stackoverflow.com/a/7938935/664833 – user664833
और ** नियंत्रक स्तर ** पर परीक्षण करने के लिए, '@ request.env ['HTTP_AUTHORIZATION'] का उपयोग करें = 'बेसिक' + Base64 :: encode64 ('उपयोगकर्ता नाम: पासवर्ड') '' तो मिलती है: your_action'। रेफरी: http://apidock.com/rails/ActionController/HttpAuthentication/Basic/ControllerMethods/authenticate_or_request_with_http_basic#197- टेस्टिंग- संरक्षित- नियंत्रक – user664833
'http_basic_authenticate_with' वास्तव में' authenticate_or_request_with_http_basic 'आंतरिक रूप से कॉल करता है। देखें [स्रोत] (https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/http_authentication.rb#L69)। – mlovic