title: Rails : Devise LDAP Authenticate 401 Unauthorized
body: <p>my company asked me to migrate an application to an Ruby on Rails Web app, but i'm not really experimented on that technology.</p>
  <p>The users have to connect to that app with their Active Directory identifiers, so i saw the gem devise_ldap_authenticatable could do that but i always have a error message when cliking &quot;log in&quot; in my server console :</p>
  <p>config/initializers/ldpa_authenticatable.rb:14:in `authenticate!'
  Completed 401 Unauthorized in 7ms (ActiveRecord: 0.2ms | Allocations: 2778)</p>
  <p>Is anyone else met the same problem ? I'm searching for hour here but all solutions i saw don't work at me...</p>
  <p>My ldap.yml file :</p>
  <pre><code>development:
   host: &lt;Host IP&gt;
   #port: 389
   attribute: sAMAccountName #cn
   base: ou=xxxxx,dc=xxxx,dc=xx
   admin_user: cn=xxxxxx,dc=xxxx,dc=xx
   admin_password: &lt;password&gt;
   ssl: false
  </code></pre>
  <p>My User.rb</p>
  <pre><code>class User &lt; ApplicationRecord
    # Include default devise modules. Others available are:
    # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
    devise :ldap_authenticatable, :registerable,
           :recoverable, :rememberable, :validatable
           
    attr_accessor :username
  
  
  end
  </code></pre>
  <p>sessions_controler.rb</p>
  <pre><code># frozen_string_literal: true
  
  class Users::SessionsController &lt; Devise::SessionsController
    before_action :configure_sign_in_params, only: [:create]
  
    # GET /resource/sign_in
    def new
      super
    end
  
    # POST /resource/sign_in
    def create
      super
    end
  
    # DELETE /resource/sign_out
    def destroy
      super
    end
  
    protected
  
    # If you have extra params to permit, append them to the sanitizer.
    def configure_sign_in_params
      added_attrs = [:username, :encrypted_password]
      devise_parameter_sanitizer.permit(:sign_in, keys: added_attrs)
    end
  end
  </code></pre>
  <p>devise.rb</p>
  <pre><code>Devise.setup do |config|
    # ==&gt; LDAP Configuration
    config.ldap_logger = true
    config.ldap_create_user = true
    config.ldap_update_password = false
    config.ldap_config = &quot;#{Rails.root}/config/ldap.yml&quot;
    config.ldap_auth_username_builder = Proc.new() {|attribute, username, ldap| &quot;#{username}&quot; }
    # config.ldap_check_group_membership = false
    # config.ldap_check_group_membership_without_admin = false
    # config.ldap_check_attributes = false
    # config.ldap_check_attributes_presence = false
    config.ldap_use_admin_to_bind = true
    # config.ldap_ad_group_check = false
  
    config.authentication_keys = [:username]
  </code></pre>
  <p>Thanks for your help i really don't know what to do...</p>