Rails : Devise LDAP Authenticate 401 Unauthorized

Viewed 18

my company asked me to migrate an application to an Ruby on Rails Web app, but i'm not really experimented on that technology.

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 "log in" in my server console :

config/initializers/ldpa_authenticatable.rb:14:in `authenticate!' Completed 401 Unauthorized in 7ms (ActiveRecord: 0.2ms | Allocations: 2778)

Is anyone else met the same problem ? I'm searching for hour here but all solutions i saw don't work at me...

My ldap.yml file :

development:
 host: <Host IP>
 #port: 389
 attribute: sAMAccountName #cn
 base: ou=xxxxx,dc=xxxx,dc=xx
 admin_user: cn=xxxxxx,dc=xxxx,dc=xx
 admin_password: <password>
 ssl: false

My User.rb

class User < 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

sessions_controler.rb

# frozen_string_literal: true

class Users::SessionsController < 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

devise.rb

Devise.setup do |config|
  # ==> LDAP Configuration
  config.ldap_logger = true
  config.ldap_create_user = true
  config.ldap_update_password = false
  config.ldap_config = "#{Rails.root}/config/ldap.yml"
  config.ldap_auth_username_builder = Proc.new() {|attribute, username, ldap| "#{username}" }
  # 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]

Thanks for your help i really don't know what to do...

0 Answers
Related