Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

OpenLDAP + NoDatabaseUserProvider its not working #755

Open
@rafaelcavalcanti

Description

@rafaelcavalcanti
  • Laravel Version: 5.5
  • Adldap2-Laravel Version: 4.0
  • PHP Version: 7.0.9
  • LDAP Type: OpenLDAP

Description:

I'm trying to connect on a OpenLDAP + NoDatabaseUserProvider but always return false. So, looking into the code i could see this:

$provider->connect();

and this:

https://github.com/Adldap2/Adldap2/blob/c406c02b095022555dbad19b4b382ce4b31420af/src/Connections/Provider.php#L253-L268

So the script will always go throught bindAsAdministrator method. If there is no issue on that, what i'm doing wrong?

But when i try by ldap function directly, its works:

$username = 'username1234';
$password = 'password1234';
$ldap_usr_dom = '@hostname.com';
$ldap_dn = "DC=echo,DC=quinstreet,DC=net";
$ldap_host = 'my.hostname.com';

$ldap = ldap_connect($ldap_host);

ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);

// verify user and password
if ($bind = @ldap_bind($ldap, $username . $ldap_usr_dom, $password)) {
  echo "binded";
  $filter = "(sAMAccountName=" . $username . ")";
  $attr = array("memberof");
  $result = ldap_search($ldap, $ldap_dn, $filter, $attr) or exit("Unable to search LDAP server");
  $entries = ldap_get_entries($ldap, $result);
  ...
} else {
  echo "Not-binded";
}

I cant upgrade PHP version and Laravel version yet.

Steps To Reproduce:

route/web.php:

Auth::routes(['reset' => false, 'verify' => false, 'register' => false]);

config/auth.php:

return [
    'defaults' => [
        'guard' => 'ldap',
         ...
    ],
    'guards' => [
        'ldap' => [
            'driver' => 'session',
            'provider' => 'ldap'
        ],
        ...
    ],
     'providers' => [
        'ldap' => [
            'driver' => 'adldap',
        ]
        ...
    ]
];

config/adldap.php:

return [
    ...
    'connections' => [
        'default' => [
              ...
              'schema' => Adldap\Schemas\OpenLDAP::class,
        ]
    ]
]

config/adldap_auth.php:

return [
     'provider' => Adldap\Laravel\Auth\NoDatabaseUserProvider::class,
     'usernames' => [
           'ldap' => [
               'discover' => 'username',
               'authenticate' => 'distinguishedname',
           ],
      ],
     'rules' => [
        Adldap\Laravel\Validation\Rules\DenyTrashed::class,
     ]
     'scopes' => [],
]

app\http\controllers\logincontroller.php@LoshowLoginForm:

public function showLoginForm() {
        $credentials = [
            'username' => 'username1234',
            'password' => 'password1234',
        ];
        var_dump(Auth::guard()->attempt($credentials));
        exit;
}

Thank You

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions