Skip to content
Advertisement

Invalid credentials adldap2/adldap2-laravel package

I am implementing LDAP authentication in laravel app. When I run this code I am getting an error.

I don’t know whether it is correct or not. I am totally new to LDAP and I don’t know how it works by seeing the documentation I have done till now.
Please help me out for setting the correct configuration settings for laravel-ldap.

Adldap  Auth  BindException (49)
Invalid credentials
 protected function attemptLogin(Request $request)
    {
       $ldap = new Adldap;
        $data = Adldap::users()->get();
       dd($data);

    }

the credential which I got from client

User Name: username
 Password: password
 IP:172.16.xx.xx
 Port: 389
 Attributes: CN=user.admin,CN=Users,DC=UATADSRV,DC=COM

my .env file

LDAP_HOSTS=172.16.xx.xx
LDAP_BASE_DN=CN=user.admin,CN=Users,DC=UATADSRV,DC=COM
LDAP_USER_ATTRIBUTE=samaccountname
LDAP_CONNECTION=default
LDAP_USERNAME=username
LDAP_PASSWORD=password

ldap.php

return [

    'logging' => env('LDAP_LOGGING', false),

    'connections' => [

        'default' => [
   'auto_connect' => env('LDAP_AUTO_CONNECT', true),

            'connection' => AdldapConnectionsLdap::class,

            'settings' => [
    'schema' => AdldapSchemasActiveDirectory::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_USERNAME'),
                'password' => env('LDAP_PASSWORD'),

                'follow_referrals' => false,


                'use_ssl' => env('LDAP_USE_SSL', false),
                'use_tls' => env('LDAP_USE_TLS', false),

            ],

        ],

    ],

];


ldap_auth.php

return [

    'connection' => env('LDAP_CONNECTION', 'default'),

    'provider' => AdldapLaravelAuthDatabaseUserProvider::class,

    'model' => AppUser::class,
    'rules' => [


        AdldapLaravelValidationRulesDenyTrashed::class,

    ],



    'scopes' => [



    ],

    'identifiers' => [

    'rules' => [


        AdldapLaravelValidationRulesDenyTrashed::class,

    ],



    'scopes' => [



    ],

    'identifiers' => [

 'ldap' => [

         //   'locate_users_by' => 'userprincipalname',
             'locate_users_by' => 'samaccountname',

            'bind_users_by' => 'distinguishedname',

        ],

        'database' => [

            'guid_column' => 'objectguid',
           'username_column' => 'username',

        ],
  'windows' => [

            'locate_users_by' => 'samaccountname',

            'server_key' => 'AUTH_USER',

        ],

    ],

    'passwords' => [



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



        'column' => 'password',
  ],


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



    'sync_attributes' => [

        'email' => 'userprincipalname',
        'username' => 'samaccountname',
        'name' => 'cn',

    ],

  'logging' => [

        'enabled' => env('LDAP_LOGGING', true),

        'events' => [

            AdldapLaravelEventsImporting::class                 => AdldapLaravelListenersLogImport::class,
            AdldapLaravelEventsSynchronized::class              => AdldapLaravelListenersLogSynchronized::class,
            AdldapLaravelEventsSynchronizing::class             => AdldapLaravelListenersLogSynchronizing::class,
            AdldapLaravelEventsAuthenticated::class             => AdldapLaravelListenersLogAuthenticated::class,
            AdldapLaravelEventsAuthenticating::class            => AdldapLaravelListenersLogAuthentication::class,
            AdldapLaravelEventsAuthenticationFailed::class      => AdldapLaravelListenersLogAuthenticationFailure::class,
            AdldapLaravelEventsAuthenticationRejected::class    => AdldapLaravelListenersLogAuthenticationRejection::class,
            AdldapLaravelEventsAuthenticationSuccessful::class  => AdldapLaravelListenersLogAuthenticationSuccess::class,
            AdldapLaravelEventsDiscoveredWithCredentials::class => AdldapLaravelListenersLogDiscovery::class,
            AdldapLaravelEventsAuthenticatedWithWindows::class  => AdldapLaravelListenersLogWindowsAuth::class,
            AdldapLaravelEventsAuthenticatedModelTrashed::class => AdldapLaravelListenersLogTrashedModel::class,

        ],
    ],

];


Thank you

Advertisement

Answer

The LDAP server is saying that your provided credentials are wrong. Are you sure, that your username and password is 100% correct? A space or any kind of invalid character?

CN=user.admin,CN=Users,DC=UATADSRV,DC=COM`

Also, is it working with ldap_bind() function?

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement