Module: ActionController::HttpAuthentication::Basic::ControllerMethods

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/action_controller/metal/http_authentication.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#authenticate_or_request_with_http_basic(realm = nil, message = nil, &login_procedure) ⇒ Object



95
96
97
# File 'lib/action_controller/metal/http_authentication.rb', line 95

def authenticate_or_request_with_http_basic(realm = nil, message = nil, &)
  authenticate_with_http_basic(&) || request_http_basic_authentication(realm || "Application", message)
end

#authenticate_with_http_basic(&login_procedure) ⇒ Object



99
100
101
# File 'lib/action_controller/metal/http_authentication.rb', line 99

def authenticate_with_http_basic(&)
  HttpAuthentication::Basic.authenticate(request, &)
end

#http_basic_authenticate_or_request_with(name:, password:, realm: nil, message: nil) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/action_controller/metal/http_authentication.rb', line 86

def http_basic_authenticate_or_request_with(name:, password:, realm: nil, message: nil)
  authenticate_or_request_with_http_basic(realm, message) do |given_name, given_password|
    # This comparison uses & so that it doesn't short circuit and uses
    # `secure_compare` so that length information isn't leaked.
    ActiveSupport::SecurityUtils.secure_compare(given_name.to_s, name) &
      ActiveSupport::SecurityUtils.secure_compare(given_password.to_s, password)
  end
end

#request_http_basic_authentication(realm = "Application", message = nil) ⇒ Object



103
104
105
# File 'lib/action_controller/metal/http_authentication.rb', line 103

def request_http_basic_authentication(realm = "Application", message = nil)
  HttpAuthentication::Basic.authentication_request(self, realm, message)
end