3
votes

I have the following configuration:

devise :database_authenticatable config.http_authenticatable = true

on request:

http://user:password@localhost:3000/

Devise ignores the http auth login and redirects to login page

any thoughts?

Regards

2

2 Answers

2
votes

What http_authenticatable give you is the ability to use your HTTP Basic Authentication credentials to log into its own authentication system. You still need to code the http_auth block by yourself, like this:

def authenticate
  authenticate_or_request_with_http_basic do |username, password|
    username == "foo" && password == "bar"
  end
  warden.custom_failure! if performed?
end

This code should go into your application controller. Make sure you are using warden.custom_failure!, otherwise the devise will enter an infinite loop of redirects.

2
votes

This worked for me

  before_filter :check_auth

  def check_auth
    authenticate_or_request_with_http_basic do |username,password|
      resource = User.find(username)
      if resource.valid_password?(password)
        sign_in :user, resource
      end
    end
    warden.custom_failure! if performed?
  end