shariff's avatar
Level 51

unable to login in laravel using LDAP package Adldap2-Laravel

Hi

I am using the Adldap2-Laravel package for authentication. I am testing using the LDAP test forum. I followed this tutorial https://jotaelesalinas.github.io/laravel-simple-ldap-auth/ But I am unable to login. I am not getting any errors. In the below code always else block is executing.

I think I have made mistake in configuration Please help me

Thank You

login controller

  protected function attemptLogin(Request $request)
    {
        
        $credentials = $request->only($this->username(), 'password');
        $username = $credentials[$this->username()];
        $password = $credentials['password'];

        $user_format = env('LDAP_USER_FORMAT', 'cn=%s,'.env('LDAP_BASE_DN', ''));
        $userdn = sprintf($user_format, $username);


        if(Adldap::auth()->attempt($userdn, $password, $bindAsUser = true)) {

            dd('working'); 
        }
        else
        {
            dd('not working');

        }  
    }

env file

LDAP_SCHEMA=OpenLDAP
LDAP_HOSTS=ldap.forumsys.com
LDAP_BASE_DN=dc=example,dc=com
LDAP_USER_ATTRIBUTE=uid
LDAP_USER_FORMAT=uid=%s,dc=example,dc=com
LDAP_CONNECTION=default

# Change from mysql to sqlite:

DB_CONNECTION=sqlite  

ldap.php

return [

    'logging' => env('LDAP_LOGGING', false),
    
    'connections' => [
        'default' => [
       'auto_connect' => env('LDAP_AUTO_CONNECT', false),

            'connection' => Adldap\Connections\Ldap::class,
            'settings' => [

                'schema' => env('LDAP_SCHEMA', '') == 'OpenLDAP' ?
                Adldap\Schemas\OpenLDAP::class :
                ( env('LDAP_SCHEMA', '') == 'FreeIPA' ?
                    Adldap\Schemas\FreeIPA::class :
                    Adldap\Schemas\ActiveDirectory::class ),

                'account_prefix' => env('LDAP_ACCOUNT_PREFIX', ''),
                'account_suffix' => env('LDAP_ACCOUNT_SUFFIX', ''),
                'hosts' => explode(' ', env('LDAP_HOSTS', 'corp-dc1.corp.acme.org corp-dc2.corp.acme.org')),
                'port' => env('LDAP_PORT', 389),
                'timeout' => env('LDAP_TIMEOUT', 5),
                'base_dn' => env('LDAP_BASE_DN', 'dc=corp,dc=acme,dc=org'),
                'username' => env('LDAP_ADMIN_USERNAME', ''),
                'password' => env('LDAP_ADMIN_PASSWORD', ''),
                'follow_referrals' => env('LDAP_FOLLOW_REFERRALS', false),
                'use_ssl' => env('LDAP_USE_SSL', false),
                'use_tls' => env('LDAP_USE_TLS', false),

            ],

        ],

    ],

];

ldap_auth.php

 'identifiers' => [
        'ldap' => [
            'locate_users_by' => env('LDAP_USER_ATTRIBUTE', 'userprincipalname'),
            'bind_users_by' => env('LDAP_USER_ATTRIBUTE', 'distinguishedname'),
        ],
    
        'database' => [
            'guid_column' => 'objectguid',
            'username_column' => 'username',
        ],
    ],

    'passwords' => [


        'sync' => env('LDAP_PASSWORD_SYNC', false),

        'column' => 'password',

    ],

  

    'login_fallback' => env('LDAP_LOGIN_FALLBACK', false),


    'sync_attributes' => [
        // 'field_in_local_db' => 'attribute_in_ldap_server',
        'username' => 'uid',
        'name' => 'cn',
        'phone' => 'telephonenumber',
    ],
0 likes
9 replies
jove's avatar

You just want LDAP to sign in? If that's the case just follow the documentation.

jove's avatar

@matheenulla Why did you change the whole post to be something else? You should instead have created a new one.

shariff's avatar
Level 51

@jove I didn't get any reply for that Post. And it's related to that only

jove's avatar

@matheenulla Well, you need to turn on logging and check the LDAP side to see what is wrong. A simple "It does not work" Does not give enough info.

Please or to participate in this conversation.