DirectoryTree / LdapRecord-Laravel

Multi-domain LDAP Authentication & Management for Laravel.
https://ldaprecord.com/docs/laravel/v3
MIT License
504 stars 54 forks source link

[Support] LoginController::causedByInvalidCredentials(): Argument DirectoryTree/LdapRecord#2 ($diagnosticMessage) must be of type string #602

Closed gnewmann closed 11 months ago

gnewmann commented 11 months ago

Environment:

Hey there,

I got following error when switching from v. 2.6 to 3.1.0 whil upgrading to Laravel 10:

App\Http\Controllers\Auth\LoginController::causedByInvalidCredentials(): Argument DirectoryTree/LdapRecord#2 ($diagnosticMessage) must be of type string, null given, called in /var/www/html/.../vendor/directorytree/ldaprecord-laravel/src/Auth/ListensForLdapBindFailure.php on line 75

Here is my LoginController Guard- Function

protected function guard()
    {
            $guard = Auth::guard();

            /** @var DatabaseUserProvider $provider */
            $provider = $guard->getProvider();

            // We will override user resolution to attempt to
            // first pre-bind to our LDAP server using the
            // users submitted login credentials.
            $provider->resolveUsersUsing(function ($credentials) use ($provider) {
                $users = $provider->getLdapUserRepository();
                $connection = $users->createModel()->getConnection();

                // Here we will assemble the users distinguished name to
                // be able to bind to our LDAP directory and allow the
                // user to query their own data from the server.

                if (!$connection->auth()->attempt($credentials['uid'], $credentials['password'], $bindAsUser = true)) {
                    return;
                }

                return $users->query()->find($credentials['uid']);

            });

            $provider->getLdapUserAuthenticator()->authenticateUsing(function () {
                // Since we have already bound using the users
                // credentials, we don't need to re-attempt
                // authentication to our LDAP server.
                return true;
            });

            return $guard;
        } else {
            // use standard guard
            return Auth::guard();
        }
}

Could you probably help me?

Thanks in advance.

Cheers

stevebauman commented 11 months ago

Hi @gnewmann! Looking into this now, thanks! 👍

stevebauman commented 11 months ago

I've just released v3.1.1 which includes a patch for this issue. Run composer update and you should be all set, thanks for the report @gnewmann! 🙏

gnewmann commented 11 months ago

@stevebauman Thank you so much! 🙏🏻 Great work! Have a great day my friend.

stevebauman commented 11 months ago

Happy to help @gnewmann! You as well 🙏