Last Updated: February 25, 2016
·
3.476K
· swlkr

Rails, Devise and Basic HTTP Auth, Oh My!

Here's how to get basic http auth working in rails with devise:

devise.rb

config.http_authenticatable = true

application_controller.rb

before_filter :authenticate

def authenticate
  authenticate_or_request_with_http_basic do |email, password|
    user = User.where(email: email).first
    !user.nil? && user.valid_password?(password)
  end
  warden.custom_failure! if performed?
end