1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/app/controllers/action_mailbox/base_controller.rb

21 lines
807 B
Ruby
Raw Normal View History

class ActionMailbox::BaseController < ActionController::Base
skip_forgery_protection
private
def authenticate
2018-10-29 13:45:24 -04:00
if username.present? && password.present?
2018-10-29 14:19:46 -04:00
http_basic_authenticate_or_request_with username: username, password: password, realm: "Action Mailbox"
2018-10-29 13:45:24 -04:00
else
raise ArgumentError, "Missing required ingress credentials"
end
end
2018-10-29 14:19:46 -04:00
# TODO: Extract to ActionController::HttpAuthentication
def http_basic_authenticate_or_request_with(username:, password:, realm: nil)
authenticate_or_request_with_http_basic(realm || "Application") do |given_username, given_password|
ActiveSupport::SecurityUtils.secure_compare(given_username, username) &
ActiveSupport::SecurityUtils.secure_compare(given_password, password)
end
end
end