jotaelesalinas / laravel-adminless-ldap-auth

Authenticate users in Laravel against an adminless LDAP server
MIT License
209 stars 33 forks source link

Exception - LdapHelper::retrieveUser() must be of the type string, integer given #46

Open stoicadl opened 4 years ago

stoicadl commented 4 years ago

Hey - I have install jotaelesalinas/laravel-adminless-ldap-auth and I have next code: LogginController.php

    protected function attemptLogin(Request $request)
    {
    .......
        if(Adldap::auth()->attempt($userdn, $password, $bindAsUser = true)) {
            // the user exists in the LDAP server, with the provided password
            return true;
        }

        // the user doesn't exist in the LDAP server or the password is wrong
        return false;
    }

    public function login(Request $request)
    {
        try {
            if($this->attemptLogin($request)){
                $user = \App\User::where('username', $request->username)->first();
                if($user != null){
                    Auth::login($user);
            return redirect()->route('home');
                }
                else{
                    \Log::info("User doesn't exist in DB");
                }
            }
            else{
                \Log::info('Wrong user/password');
            }

        } catch (Exception $e) {
            \Log::error('ErrCatch: ' . $e->getMessage());
        }
    }

But after login, on http://127.0.0.1:8000/home I get this exception:

Argument 1 passed to JotaEleSalinas\AdminlessLdap\LdapHelper::retrieveUser() must be of the type string, integer given, called in D:\xampp\htdocs\TestLaravelLDAP\vendor\jotaelesalinas\laravel-adminless-ldap-auth\src\AdminlessUserProvider.php on line 39

What am I doing wrong?

github-actions[bot] commented 4 years ago

Hi #! Welcome to this repo.

jotaelesalinas commented 4 years ago

Hi @stoicadl , you should not touch LoginController. Have you followed the instructions? Have you been able to login inside Tinker?

stoicadl commented 4 years ago

I made a fresh install, step by step. When I try to login inside Tinker, I get next warnings:

>>> Auth::attempt(['username' => 'einstein', 'password' => ''])
PHP Warning:  ldap_search(): Search: Operations error in D:/xampp/htdocs/TestLaravelLDAP/vendor/adldap2/adldap2/src/Connections/Ldap.php on line 286
PHP Warning:  ldap_get_entries() expects parameter 2 to be resource, boolean given in D:/xampp/htdocs/TestLaravelLDAP/vendor/adldap2/adldap2/src/Connections/Ldap.php on line 143
=> false

My config in .env is:

LDAP_SCHEMA=OpenLDAP
LDAP_HOSTS=dan.ro
LDAP_BASE_DN=dc=dan,dc=ro
LDAP_USER_SEARCH_ATTRIBUTE=uid
LDAP_USER_BIND_ATTRIBUTE=uid
LDAP_USER_FULL_DN_FMT=${LDAP_USER_BIND_ATTRIBUTE}=%s,${LDAP_BASE_DN}
LDAP_CONNECTION=default

AUTH_USER_KEY_FIELD=username